Member Avatar

Hi, I am using WinSock library for sending data over network, and I have a problem. I know how to send data in one struct and receive it on the other side, because there is constant size of structure. But what if I have more structures, each one with different size? Now I have one struct that contains locations of players and other with in-game messages. When I am about to receive struct, I don't know which one is being sent. Is there a "trick" how to do that? Thanks for help.

Member Avatar
0
8
Member Avatar

I am writing a sample chat-like function to learn how to use sockets in unix. I am using gcc. To send between clients of a tcp connection I need to encapsulate a bunch of different data: [code=c] typedef struct { short type; int messageID1; int messageID2; short messageID3; int ipAddr; short tcp_port; short udp_port; int pid; int payloadLength; char * stringSend; } ping_packet; [/code] After filling out this info, I am using memmove() to put all of the data into a char array and use send() to send the information. All of the sent data (except sendString) is converted to …

Member Avatar
0
3
Member Avatar

[CODE]while(size!=0) { printf("loop start"); printf("File Size in int: %d \n",size); byte_count = recv(sock,recv_data, 1024,0); recv_data[byte_count] = '\0'; printf("hhahaha %d \n",10); printf("char is:%c \n",recv_data[0]); //fputc(recv_data[0], fpW); size=size-1; printf("loop end"); } fclose(fpW); This is a piece of Client side code .. i am sending data from Server Side but when i receive it on client side the recv call is blocked the code how m i sending data from server is: FILE *fp; int ch; if((fp = fopen("file.txt","rb"))==NULL) { printf("Cannot open Source file.\n"); exit(1); } struct stat fileInfo; stat("file.txt", &fileInfo); int size=(int)fileInfo.st_size; printf("File Size: %d \n",size); fflush(stdout); char msg1[10]; sprintf(msg1,"%i",size); printf("File Size: …

Member Avatar
0
6

The End.