Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I test a simple TCP/IP socket program . In server , i use C program and in client , i use java program. When i send back result from server to client , client can't read data .

server send data like the following format ,

send(connected, 100,strlen(100),0);

client receive like the following format,
BufferedReader fromServer =
new BufferedReader(
new InputStreamReader(socket.getInputStream()));

String line = fromServer.readLine();
System.out.println("Client received: " + line + " from Server");


pls help me.
Posted
Comments
Richard MacCutchan 8-Oct-15 4:02am    
Help with what? you have not explained what the problem is. I suggest you add some diagnostic code to your program or use the debugger to step through and check what is happening.

1 solution

your send function looks strange. Does it work?

I would write it a little better
C++
send(connected, "100",strlen("100"),0);

normally is such code written in that way
C++
 int cnt = 100;//or some dynamic value
 char *buffer = new char[cnt];
memcpy( buffer, someSourceData, dataSize );//smaller than cnt
send(connected, buffer,dataSize,0);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900