/ Published in: C++
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
#pragma pack(1)
typedef struct
{
int id;
char[50] text;
} MESSAGE;
// Send a message
MESSAGE msg;
msg.id = 1;
strcpy(msg.text, "This is a test");
send(socket, (char*)&msg);
// Receive a message
char buffer[100];
recv(socket, buffer, 100);
MESSAGE* msg = (MESSAGE*)buffer;
printf("id=%d\n", msg->id);
printf("text=%s\n", msg->text);
URL: http://geekswithblogs.net/taylorrich/archive/2006/08/21/88665.aspx
Comments
 Subscribe to comments
                    Subscribe to comments
                
                