Sender side:
Receiver Side:Code:int len = strlen(str);
write(sock,&len,sizeof(int));
write(sock,str,len);
Code:int len;
read(sock,&len,sizeof(int));
char* str=(char*)malloc(len*sizeof(char));
read(sock,str,len);
Printable View
Sender side:
Receiver Side:Code:int len = strlen(str);
write(sock,&len,sizeof(int));
write(sock,str,len);
Code:int len;
read(sock,&len,sizeof(int));
char* str=(char*)malloc(len*sizeof(char));
read(sock,str,len);
what are return values of write and read?
what does it mean - "doesn't work" - how do you check it?
PS. And this is C, why to post on C++ board?
maybe because write() and read() aren't part of the socket API !?
also, what OS? I don't see any of the initialization or setup functions in that snippet. without some more context information it could be anything, a bad pointer, a bad socket, unitialized socket stack, improperly installed drivers, poor feng shui, etc.