Networking Forums

Networking Forums > Computer Networking > Linux Networking > Variable Length Packets

Reply
Thread Tools Display Modes

Variable Length Packets

 
 
Marcia Hon
Guest
Posts: n/a

 
      02-09-2004, 02:40 AM
Hi,

I would like to ask you a question regarding send and read buffers/packet
lengths. I would like to know how I can make this size variable meaning that
it corresponds to the sending message size.

So far, my program works when I force the buffer sizes to be a certain size,
BUFFER_MAX. I would like to have this according to the message size. I have
tried:

Bytes_sent = send(server_socket, sbuffer, *sbuffer, 0);

Where *sbuffer stores the message size, thereby sending the full message.

Let's say that the message is 7 bytes, where the first 2 bytes state the
message size.

On the receiving end I want to read the message size, and then read
according to how many bytes are left. So I have the following:

Bytes_received = read(client_socket, rbuffer, 2);

Size_of_packet = *rbuffer;

Bytes_received += read(client_socket, (rbuffer+2), (Size_of_packet-2));

Now when I try to read the data in rbuffer, I get values that are different
from those sent.

Please could you help.



My second approach is to use MSG_PEEK and MSG_WAITALL for the receiving end.

Bytes_received = recv(client_socket, rbuffer, 2, MSG_PEEK);

Bytes_received += recv(client_socket, rbuffer, *rbuffer, MSG_WAITALL);

Here, I am able to receive the first two bytes from the first call, but all
the other data are zero.



Please help.

Thank you,

Marcia Hon


 
Reply With Quote
 
 
 
 
Markku Kolkka
Guest
Posts: n/a

 
      02-09-2004, 11:26 AM
Marcia Hon wrote:

> Bytes_sent = send(server_socket, sbuffer, *sbuffer, 0);
>
> Where *sbuffer stores the message size, thereby sending the full
> message.
>
> Let's say that the message is 7 bytes, where the first 2 bytes state
> the message size.


Are you really running on a system where sizeof(size_t) == 2 ? In a
normal IA32 Linux system you need 4 bytes for the len parameter of
recv().

--
Markku Kolkka
(E-Mail Removed)
 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(sky) ADSL variable speeds Ric Home Networking 6 12-18-2008 03:24 PM
Variable signal David W Allen Home Networking 0 04-05-2006 07:35 PM
Variable I/P address Paul Aitman Home Networking 14 12-06-2005 03:00 PM
The variable bit cpu Skybuck Flying Windows Networking 0 07-30-2005 07:04 PM
Variable IP question zjustice Broadband 3 06-02-2005 11:00 PM



1 2 3 4 5 6 7 8 9 10 11