From: ronkhu <ronkhu@ntsp.nec.co.jp>
To: Earl Lapus <lapuz.rl@mp.ncos.nec.co.jp>,
"Lejanson C. Go" <g_l-go@tmg99.ntes.nec.co.jp>,
linux-c-programming@vger.kernel.org
Subject: socket send and recv
Date: Thu, 07 Aug 2003 18:46:18 +0800 [thread overview]
Message-ID: <3F322DFA.2030509@hq.ntsp.nec.co.jp> (raw)
i have a client program which sends a sequence of bytes everytime
anything(plus carriage return) is inputted into STDIN...
but the problem lies in the receiving end of the socket connection...
with a single call of the recv() function, multiple messages sent by the
client are concatenated into one stream..
unsigned char msg[] = { 0x00, 0x00, 0x00, 0x20, 0x20, 0x01, 0x00,
0x00, 0xB2, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
0x00, 0x20, 0x03, 0x06, 0x03, 0x16, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF };
while(1)
{
FD_ZERO( &readSet );
FD_SET( 0, &readSet );
if ( select( 1, &readSet, NULL, NULL, NULL ) > 0 )
{
read( 0, temp, 10 );
send( sock, msg, 40, 0 ));
}
}
because of this scenario, i was forced to add a sequence of bytes that
would serve as a delimter separating the messages. The server program
would then pre-parsed the message by sub dividing the data using the
delimeter sequence of bytes
next reply other threads:[~2003-08-07 10:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-07 10:46 ronkhu [this message]
2003-08-07 11:40 ` socket send and recv Luciano Miguel Ferreira Rocha
2003-08-07 22:03 ` John T. Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3F322DFA.2030509@hq.ntsp.nec.co.jp \
--to=ronkhu@ntsp.nec.co.jp \
--cc=g_l-go@tmg99.ntes.nec.co.jp \
--cc=lapuz.rl@mp.ncos.nec.co.jp \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).