I'm running into a problem with sending packets between a java client and a c++ server over a tcp/ip socket.
the data being sent between the client and server is a plain text string.
the problem I'm having is the java client can send packets to the server and the server can process the strings send without a problem. However, when I send a string from the server to the client the java client either interprets it as being a blank string or as random characters.
here's the relevant c server code
Here's how I setup the buffer
Here's an example of the first thing I try to write from the server to the client and how I put it into the buffer.
char* messageBuf = (char*)malloc(sizeof(char)*1025);
Here's the function call I use to send the packet through the socket
here's the relevant java client code
perror("Server: write error");
I setup my socket in java with
setup my input output streams in java with
s = new Socket("127.0.0.1", serverPort);
read from the stream in java using
DataOutputStream out = new DataOutputStream(s.getOutputStream());
DataInputStream in = new DataInputStream(s.getInputStream());
any help would be very much appreciated.
char bytes = new char;
data = bytes.toString();