Note that there are some explanatory texts on larger screens.

plurals
  1. POSend() message include some field in TCP socket (C Linux)
    text
    copied!<p>System include some clients and server. Client send message to server have 3 types of message:</p> <ul> <li>Connection setup: User type command-line: remote-chat <code>&lt;IP addr server&gt;</code>: <code>&lt;port addr server&gt;</code> <code>&lt;IP address client&gt;</code>: <code>&lt;port addr client&gt;</code>, a link TCP connection will be established between the client and server chat. After the TCP connection is set, the client sends the connection setup information, including some fields: <ul> <li>The message identifier: is a 32-bit integer. With Connection setup message, this field equal to 0.</li> <li>Field IP address of client 2 (client 1 call), Port address of client 2.</li> </ul></li> </ul> <p>Server receive this message. Then create a connection to client 2.</p> <ul> <li>Data exchange: used to exchange data between client and server. Include some fields: <ul> <li>The message identifier: is a 32-bit integer. With Data exchange message this field = 1</li> <li>The data length: an integer indicating the length of the text message.</li> <li>The data text field: contains text messages to exchange.</li> </ul></li> </ul> <p>When receiving data sent from client 1, chat server transfer text messages from client 1 to client 2 (client 2 also using data exchange message).</p> <p><strong>So my question is: how do I send the message with some field? I already know send string by function send(). Here I have to send message Connection Setup or Data exchange with some field then I whether used pack in client side then unpack in server side or not? Please give me some solution for this problem?</strong></p> <p>I think use:</p> <pre><code>typedef struct _ConnectionSetup_Message { int message_ID; // 0 ConnectionSetup message unsigned int Port; unsigned shor IP; } HELLO_Message; typedef struct _DataExchange_Message { int message_Length; int message_ID; // 1 for DataExchange message char *text; } DataExchange_Message; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload