I send an integer from a C client to a java server and it worked perfectly. But when i tried to do the same thing with a string i got and error this is the client code to send the String
char clientString[30];
printf("String to send : \n");
if( send( to_server_socket, &clientString, sizeof( clientString ), 0 ) != sizeof( clientString ) )
{
printf( "socket write failed");
exit( -1 );
}
And the java code to read it
DataInputStream din = new DataInputStream(socket.getInputStream());
String clientString=din.readUTF();
System.out.println(clientString);
Error
java.io.EOFException at java.io.DataInputStream.readFully(DataInputStream.java:180) at java.io.DataInputStream.readUTF(DataInputStream.java:592) at java.io.DataInputStream.readUTF(DataInputStream.java:547) at ServiceRequest.run(ServiceRequest.java:43) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:680)
EDIT :I tried using din.readLine()
,I don't have the error anymore but if i type fffffff12 on the client i got fffffff12`?7E^Ê?h in the server
&clientString
andsizeof(clientString)
may not do what you expect them to. Please edit your question to include the declaration ofclientString
. – Some programmer dude