I have a socket sever is written by java, it always listens on specific port. I wrote a client in Java and it could connect to the server but when I created a client in C#, I could not connect to Server.
I just want to send a short value to start a java server.
I guess the problem come from the endianess (little-endian, big-endian) and I have several days to research but can not solve this issue.
I post more information about my problem
I use java.io.* and java.net.*. My java code
out = new ObjectOutputStream(requestSocket.getOutputStream());
out.flush();
public static final short CLIENT = 0;
out.writeShort(CLIENT);
out.flush();
and with c#, I use System.Net.Sockets. My C# code is below:
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
...
short sClient = 0;
if (BitConverter.IsLittleEndian) sClient = IPAddress.HostToNetworkOrder(sClient);
NetworkStream ns = new NetworkStream(socket);
BinaryWriter bw = new BinaryWriter(ns);
bw.Write(sClient);
The java code can connect to the java server but the c# code can not :(. The output error from java server is "Exception while getting socket streams"
Anyone can help me about this problem, thanks in advance