473,396 Members | 1,968 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,396 software developers and data experts.

Packet overflow in simple client/server

I'm trying to send 15000 packets using a basic client/server and measure the delays but after so many packets sent it starts going a bit out of sync. The client always reports sending 320bytes but the server starts to recieve 140 and 180 now and again.
The server recieves using:
Expand|Select|Wrap|Line Numbers
  1.     char acReadBuffer[kBufferSize];
  2.     int nReadBytes;
  3.     do {
  4.         nReadBytes = recv(sd, acReadBuffer, kBufferSize, 0);      
  5.         if (nReadBytes > 0) 
  6.         {
  7.             cout << "Received " << nReadBytes << 
  8.                     " bytes from client." << endl; 
  9.  
And the client sends using:
Expand|Select|Wrap|Line Numbers
  1. if (send(sd, kpcEchoMessage, kEchoMessageLen, 0) != SOCKET_ERROR) 
  2.  
when sd is the socket, the kpcEchoMessage is a message of 320bytes and kEchoMessageLen is the length in bytes of kpcEchoMessage. As well as that:
const int kBufferSize = 1024;
Is declared at the start. I don't usually post looking for help but i'm running out of time for a deadline, i've been looking at this for a fair while now and a month ago i'd never seen any c++ code before.
Thanks for any help.
Mar 13 '07 #1
9 2423
sicarie
4,677 Expert Mod 4TB
I'm trying to send 15000 packets using a basic client/server and measure the delays but after so many packets sent it starts going a bit out of sync. The client always reports sending 320bytes but the server starts to recieve 140 and 180 now and again.
The server recieves using:

char acReadBuffer[kBufferSize];
int nReadBytes;
do {
nReadBytes = recv(sd, acReadBuffer, kBufferSize, 0);
if (nReadBytes > 0)
{
cout << "Received " << nReadBytes <<
" bytes from client." << endl;

And the client sends using:

if (send(sd, kpcEchoMessage, kEchoMessageLen, 0) != SOCKET_ERROR)

when sd is the socket, the kpcEchoMessage is a message of 320bytes and kEchoMessageLen is the length in bytes of kpcEchoMessage. As well as that:
const int kBufferSize = 1024;
Is declared at the start. I don't usually post looking for help but i'm running out of time for a deadline, i've been looking at this for a fair while now and a month ago i'd never seen any c++ code before.
Thanks for any help.
Is this a problem with the size of the packets, or the number that are sent? If it's the number that is sent, you could structure it roughly around a TCP-esque model and have an ACK sent back after every so many packets (and not have the server send the next batch until those 4 have been acknowledged...).
Mar 13 '07 #2
lqdeffx
39
not knowing the complete story, obviously...and sometimes the case always, if you are on a deadline why just use the infamous ping. you can specify how big the packets are and how many you want to send.
Mar 13 '07 #3
Thanks for the help. I can't use ping because I have to build it myself, and I have timestamping code in it to measure delays. I don't think it's a problem with the size, they're all 320 bytes. I could probably use ACK, but the idea is that i'm simulating a phone call (I know VoIP uses UDP but i won't go into that unless i have to) and I need to keep it as quick as possible. I think the problem is that the original code sent the packet, the server recieved it and echoed it back, and the client checked if it was the same packet and then moved on. Somehow by getting rid of the sanity check it's caused a problem. It's just that after so many iterations the server starts recieving the wrong amounts and recording too many recieved packets, i.e. after one session the client sent 15000 but the server recieved 15338. I'm just guessing here but it is possible the server is recieving a packet, then somehow the buffer fills up or something and the server registers as moving onto a new packet? I don't really know what i'm talking about. Thanks for the help again.
Here's a few things that may or may not be useful
The packet message:
const char* kpcEchoMessage = "This is a message containing 320 bytes aaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
"1234567890abcdefghijABCDEFGHIJK1MNOPQ";

The Sending method:
Expand|Select|Wrap|Line Numbers
  1. // Send the string to the server
  2. if (send(sd, kpcEchoMessage, kEchoMessageLen, 0) != SOCKET_ERROR) 
  3. {
  4.     return 1;
  5. }
  6. else 
  7. {
  8.     return 0;
  9. }
  10.  
The server packet recieve:
Expand|Select|Wrap|Line Numbers
  1.  
  2. char acReadBuffer[kBufferSize];
  3. int nReadBytes;
  4. do {
  5.     nReadBytes = recv(sd, acReadBuffer, kBufferSize, 0);      
  6.     if (nReadBytes > 0) 
  7.     {
  8.                 cout << "Received " << nReadBytes << 
  9.                     " bytes from client." << endl; 
  10.                 }
  11.     else cout << "Unable to open file";
  12.  
  13.         }
  14.         else if (nReadBytes == SOCKET_ERROR) 
  15.         {
  16.             return false;
  17.         }
Mar 13 '07 #4
sicarie
4,677 Expert Mod 4TB
If you're going to use UDP, the point is that you can lose packets, they can be dropped, but the bulk of them get through - like with voice, you dont' want a word coming in 5 seconds later and interjecting to the conversation, you want that dropped, so the person either picks up on it and repeats themselves, or it was one packet (maybe a quarter of a syllable - I have no real idea how much voice is in one packet, I'm just using it as an example), and you can still understand the person.

If you need all the bytes of the packets, I would not use UDP or that type of connection model (without a check), for exactly the reason you are seeing. What is the goal of the project?
Mar 13 '07 #5
lqdeffx
39
I am still learning about sockets myself but you seem to be making some assumptions that I have learned you shouldn't. Just because you specified a packet at whatever size, does not mean that is what is being sent out. Your buffer, which you seem to understand is what your computer sends/recieve packets to/from has a limit as well. To add to that, just because you sent a packet does not mean it will be correctly received, even within a LAN its possible that packets get lost or corrupted and need to be resent. On another note, you stated that you didn't want to use UDP and that you wanted to keep it as quick as possible, well UDP, being a connectionless protocol, is much faster than TCP/IP because of the less checks and acknowledgments it does. Your code, what was given, looks to be pretty straightforward, unless I'm missing something. (*looks to sicarie to possibly simplify the matter.) ... to late!
Mar 13 '07 #6
sicarie
4,677 Expert Mod 4TB
(*looks to sicarie to possibly simplify the matter.)
We're in trouble...

But lqdeffx is right, there might be something going on with the packets you're sending. Did you try downloading a packet capturing program such as Ethereal or Wireshark and grabbing the packets you're sending out?
Mar 13 '07 #7
Originally, it was to measure VoIP delays over 802.11 wireless networks but right now that's a bit out of reach, and i'm working on getting this model working. It's all a bit of a mess but still i'm gonna try to get it working. I think what you're saying is that there are packets being lost, but from looking at the results it seems that the packets are being read wrong
i.e.
The server will display
320 bytes recieved from client....
for a long time and then come up with
180 bytes recieved from client....
140 bytes recieved from client....
320 bytes revieved from client....
which looks to me like it's recieving most of them fine, but every now and then it's taking in one packets and splitting it into 2 (140+180 bytes). Even stranger (to me) is that sometimes it's like it recieves a fraction of a packet, recieves a few full packets, then goes back and gets the rest of the part-packet
i.e.
320 bytes recieved from client....
80 bytes recieved from client....
320 bytes recieved from client....
320 bytes recieved from client....
240 bytes recieved from client....
Ahh i don't know. I thought this was TCP code but what you said put me off. I really don't have a clue, the guy over the project said it was TCP but we were supposed to get rid of the sanity checking and packet reply from server, so what we have now is probably some mutant, using TCP architecture but with a UDP layout.
Mar 13 '07 #8
sicarie
4,677 Expert Mod 4TB
Sometimes TCP will decide to cut up your data packet, so it's possible that the 180 size datagrams are full packets you were trying to send, but they got cut up somewhere.

I would recommend looking at the packets going across the network - checking the data payload and seeing what is in there - if your full packet is, or if it's getting cut off. Then we can rule out that aspect of TCP being the culprit.
Mar 13 '07 #9
lqdeffx
39
I agree, as if I wouldn't though come on. One thing to remember, especially when using sockets and transferring data over a medium is you can not assume anything. Meaning, do not assume that the 3rd packet you sent will be the 3rd packet recieved or the size for that mater too. If anything, I would be more concerned about the integrity of the data than how many packets it took to get from 1 node to the other. That is, if I was concerned about the data to begin with, TCP vs UDP.
Mar 13 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: chris Struhar | last post by:
I have to transmit an icon across the internet from a client to a server which handles connections from many different clients and just continuously loops through receiving data from the buffer....
12
by: David Sworder | last post by:
Hi, I'm writing an application in which a client (C#/WinForms) and server (C#/service) interact with one another. The client establishes a "session" with the server but for scalability reasons...
6
by: SRLoka | last post by:
I am designing a UDP server(still on paper) that will receive data from various client applications(residing on PocketPCs using GPRS) I am using Richard Blum's 'C# Network Programming' as my guide....
10
by: PH | last post by:
Hi guys! I need to get the remote EndPoint from when I receive packets when listening in a local port in my computer. I'm using UDP (connection-less) so I only bind the socket to my...
7
by: owolablo | last post by:
Hi, I'm writing a program that sends 1500 bytes of data at once, from the client to the server. However, the packet is broken down into 3 different segments of 500 each before getting to the...
1
by: Ken Fine | last post by:
I have been investigating programmatically downloading FLV content from various sites ("video scraping"??) Many interactive GUI tools do this, such as the Orbit downloader. At the heart of them...
1
by: quddusaliquddus | last post by:
Hi :D, I am sending data to server via TCP IP Connection. I am using a continuous loop at the server end - that accepts new clients and while streams can be read, it reads data stream. ...
4
by: plowgrammer2010 | last post by:
I have simple udp client and server using UdpClient class in .net frame work 2.0 My Ip address is 192.168.5.20 and client ip address is 192.168.1.25 and we client pc and mine are on same network...
1
by: alex21 | last post by:
Ok i have never before tried networking in my programming, so this is the first time i have tried anything like this. But i am trying to make an application which acts as a medium between a server...
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:
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.