Socket Programming
-
Hello Freinds, I want to transfere one structure from client to server. structure contains one String and INT data, INT is the length of that string. I am trying send(); function of CSocket to transfere the structure but I am getting some garbage at server end and missing my strings address. Can anyone pl's help me. I have dought that the function I am using may not be currect. Thanks. Dinesh.
-
Hello Freinds, I want to transfere one structure from client to server. structure contains one String and INT data, INT is the length of that string. I am trying send(); function of CSocket to transfere the structure but I am getting some garbage at server end and missing my strings address. Can anyone pl's help me. I have dought that the function I am using may not be currect. Thanks. Dinesh.
why don't you directly transfered the string to the server!,as
recv
winsock api returnd with total length of data recieved. something like this way, i am giving win32 based code Client End:char szString="Codeproject";
UINT nszLen=strlen(szString)+1;//Extra NULL character
send(hSendingSocket,szString,nszLen,0);Server End
char szString[1024];
int nTotalBufferLen=1023;//one for NULL character//recv data
int nRecv=recv(hRecvingSocket,szString,nTotalBufferLen,0);//complete string
szString[nRecv]=NULL;
"I Think this Will Help" [Vote One Here,.....]
visit me at http://www.thisisalok.tk
-
Hello Freinds, I want to transfere one structure from client to server. structure contains one String and INT data, INT is the length of that string. I am trying send(); function of CSocket to transfere the structure but I am getting some garbage at server end and missing my strings address. Can anyone pl's help me. I have dought that the function I am using may not be currect. Thanks. Dinesh.
Dinesh, I recommend using
CSocketFile
andCArchive
. They work beautifully! :cool: /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com -
Dinesh, I recommend using
CSocketFile
andCArchive
. They work beautifully! :cool: /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.comThanks Ravi, I will try this option. Dinesh.
-
Hello Freinds, I want to transfere one structure from client to server. structure contains one String and INT data, INT is the length of that string. I am trying send(); function of CSocket to transfere the structure but I am getting some garbage at server end and missing my strings address. Can anyone pl's help me. I have dought that the function I am using may not be currect. Thanks. Dinesh.
Hi friend, Maybe the problem is that, if you are using TCP/IP protocol, the structure is divided as multiple packets on the network, so you should first send the size of the structure (string + int), then use recv() and check that the number of bytes received are equal to the size of the structure before using the structure, or USE UDP/IP. something like this:
int nRecv=0; while(nRecv //now i am sure i received the whole message, not just few packets //now use the structure Mohammad Gdeisat
-
Hi friend, Maybe the problem is that, if you are using TCP/IP protocol, the structure is divided as multiple packets on the network, so you should first send the size of the structure (string + int), then use recv() and check that the number of bytes received are equal to the size of the structure before using the structure, or USE UDP/IP. something like this:
int nRecv=0; while(nRecv //now i am sure i received the whole message, not just few packets //now use the structure Mohammad Gdeisat
Hi Mohammad, Thanks for the help, I will try this option. Regards, Dinesh.