I am new to socket programming. Need to send multiple strings one-by-one to server and collect the resulting string.
Now the problem is that using send/write function in client, all the strings are read in one go from server.
//client.c
sendString(serversocket,"str1");
sendString(serversocket,"str2");
sendString(serversocket,"str3");
//server.c
char *buff=readstring(clientsocket);
printf("%s",buff) ;//output : str1str2str2
Need to get str1
, str2
and str3
...
I need to make it as receive one after another. How can I do this? Any help would be appreciated.
A TCP socket is a byte stream - You will have to split up the data on the receiving end.
For strings, you can do this in e.g. one of these two ways:
Client:
Server:
Or, you can use 0-termination:
Client:
Server:
You will have to handle both of these two cases on the server end:
recv()
recv()