473,388 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Variable Length Packet

Hi,

I am using read and send of the socket library. I would like to send packets
that have variable length, and I would like to read these packets. I have
designated the first 2 bytes to state the size of the packet.

So far, my program works when I force the packet size to be the size of the
buffer. However, when I try and change the buffer size to correspond to the
packet size, the receiving end does not work. I try to receive the first two
bytes in order to read the size. This works. However, when I read from the
buffer again to get the rest of the packet it does not work.

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));

This code does not work. I am not able to read the packet.

Please help.

Thanks,

Marcia Hon
Nov 14 '05 #1
0 1895

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Paul | last post by:
Hi, (First apologies if this is not the most relevant place to post this but I wasn't sure of where was and I am writing my app in VB.) I'm attempting to parse a binary file for which I have...
1
by: Kifah Abbad | last post by:
hi guys, Supposidly i have a function code:-------------------------------------------------------------------------------- decode_ip(u_char *packet, u_char flags)...
8
by: Fernando Barsoba | last post by:
Hi, I decided to start a new topic about my memory allocation question. One of the answers was that variable length arrays are possible using C99. I found this topic that also mentions it. ...
2
by: Kevin Frey | last post by:
Hello, I want to do the equivalent of this in Managed C++: void MyFunc( int n ) { Byte mybuffer = new Byte; socket.Receive( mybuffer ... ); }
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
4
by: Roy Epperson | last post by:
I'm not finding what the maximum number of characters that a statement can be. Anyone know where I can find that spec?
41
by: koolj96825 | last post by:
What is your opinion on function length? Are extra long functions poor style? I have been working on my winprocs and some are getting rather long in length. I could break them up into pieces,...
3
by: psroga | last post by:
Can anyone look at this code and let me know why pthread_mutex_unlock and pthread_mutex_lock are giving me the "phtread_mutex_unlock" was not defined in this scope error. I am compiling the code...
4
by: danomano | last post by:
The code below works fine. As of now I just set the buffer length real big and all is good. However, I hate the impreciseness of that. So my question in general is how do I know what length to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.