- #1
user366312
Gold Member
- 89
- 3
- TL;DR Summary
- I have a C# server. I need to connect a Java client to it, and make them interact.
The following is a client-side C# code:
I have written the following Java code:
But, my java code isn't working.
C#-Server and C#-clients are running okay. The C#-server seems to be not receiving the string sent by Java client.
How can I do what I need? What would be the Java equivalent of this code?
C# client:
string Host = "localhost";
int Port = 2000;
TcpClient Tcp = new TcpClient(Host, Port);
NetworkStream stream = Tcp.GetStream();
reader = new BinaryReader(stream);
writer = new BinaryWriter(stream);
writer.Write("Hello");
string str = reader.ReadString();
I have written the following Java code:
Java Client:
InetAddress ip = InetAddress.getByName("localhost");
int PORT_NO = 2000;
Socket socket = new Socket(ip, PORT_NO);
// obtaining input and out streams
DataInputStream reader = new DataInputStream(socket.getInputStream());
DataOutputStream writer = new DataOutputStream(socket.getOutputStream());
writer.writeChars("Hello");
String str = reader.readUTF();
But, my java code isn't working.
C#-Server and C#-clients are running okay. The C#-server seems to be not receiving the string sent by Java client.
How can I do what I need? What would be the Java equivalent of this code?