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

Crazy Send and Recv behaviour

i have this sort of server - client (which is described as servents in
the gnutella specification, and it's what i'm trying to do..)
And this is what happens:
SOMETIMES, when computer A sends through a socket 37bytes, Computer B
recieves 37bytes, and prints certain info about it.
Now, other more irritating TIMES, computer A has to send two Packet,
one first, then another, both 37bytes long , the Send function on
computer A Tells me, Hey! i sent 37bytes, and then, the same, So i Say,
OK, computer A sent 2 37b messages. Now the funny part is.. Computer B
says Hey! i recieve something.. It's 74bytes (37 * 2) long!!! So i
kinda have a problem. Again, This happens sometimes!. And IN FACT,
after checking with ethereal (sniffer) there are Exactly 74bytes
travelling through the net!. So What should i think.. computer A said i
have to send 37b but i wont do it now, now i have to send another 37b
msg? Ok, i'll send both within the same Frame Eth, TCPIP packet!; just
to bug computer B, Je JE!.
I know that sometimes the OS may decide whether to split packets
because thet're long or whatever (i read some of the Beej's tutorials
on sockets) but i dont think this is the case.

this is crazy for me. Cant handle it.
Please Help!.

ps: i'll try to give you some of the code.

Nov 15 '05 #1
4 1817
>i have this sort of server - client (which is described as servents in
the gnutella specification, and it's what i'm trying to do..)
And this is what happens:
SOMETIMES, when computer A sends through a socket 37bytes, Computer B
recieves 37bytes, and prints certain info about it.
Now, other more irritating TIMES, computer A has to send two Packet,
one first, then another, both 37bytes long , the Send function on
computer A Tells me, Hey! i sent 37bytes, and then, the same, So i Say,
OK, computer A sent 2 37b messages. Now the funny part is.. Computer B
says Hey! i recieve something.. It's 74bytes (37 * 2) long!!! So i
If you are using TCP, packet boundaries are not preserved. Better
learn to live with it. It won't change. You can also get your
37 byte packet received as 23 and 14 byte pieces. Well, actually
the splitting up is more likely to happen with much larger packets,
say, 8k, but it still can happen with packets the size you are sending.
this is crazy for me. Cant handle it.
LEARN TO HANDLE IT. Or use UDP, which has its own problems,
like duplicate packets, missing packets, and packets out of order.
Please Help!.


Gordon L. Burditt
Nov 15 '05 #2
On 19 Oct 2005 10:30:33 -0700, if*****@gmail.com wrote:
i have this sort of server - client (which is described as servents in
the gnutella specification, and it's what i'm trying to do..)


Off topic here, where we discuss the C programming language. At a
guess, I'd say comp.unix.programmer would be more useful to you.
--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 15 '05 #3
if*****@gmail.com wrote:

i have this sort of server - client (which is described as servents in
the gnutella specification, and it's what i'm trying to do..)
And this is what happens: [...send'ing two 37-byte packets may result in recv'ing one 74-byte packet...]
[...] this is crazy for me. Cant handle it.

[...]

Sockets are OT for clc, so if you want specifics, you'll probably need
something like comp.unix.programmer.

However, imagine program A fwrite()ing 37 bytes twice, and program B
fread()ing 74 bytes. How is this different?

If you can't handle it, then you need to find someone else who can
handle it to write it for you.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Nov 15 '05 #4
That behaviour is to be expected. As another poster said, TCP does not
preserve packet boundaries.

I would add that you should view a tcp connection as a stream. If you
are _always_ sending 37 bytes, then you should query the socket to know
if it has at least 37 bytes for you to consume, in which case you can
then perform a read for 37 bytes (and not more, since you want eat up
what should be part of your next read).

Otherwise, if you ever send more than one type of data, you should
consider adding a header to your data chunks specifying the size of the
chunk itself.

But this is off topic for this group.

Nov 15 '05 #5

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

Similar topics

5
by: daniel.shaya | last post by:
I'll try and keep this brief so in a nutshell: I have large distributed java system running on a Windows 2003 server (4cpu 8Gb memory). Periodically the following exceptions occurs in the...
4
by: jas | last post by:
I have a basic client/server socket situation setup....where the server accepts a connection and then waits for commands. On the client side, I create a socket, connect to the server...then I...
6
by: Tom | last post by:
I try to write a simple tcp based job queue server. It's purpose is to get commands from a client and store them in a queue (STL). The server has a thread which checks periodically the queue,...
14
by: Professor Yonce | last post by:
I have made form for E-Mail. I have entered code but the Import system does not work. It has squiggly line underneath it showing it is not communicating. It Will not build. Public Class...
10
by: Hendrik van Rooyen | last post by:
While doing a netstring implementation I noticed that if you build a record up using socket's recv(1), then when you close the remote end down, the recv(1) hangs, despite having a short time out...
1
by: danfolkes | last post by:
Hey Everyone, I am trying to send repeated messages from a "Node" to a "Server". It works the first time I send the from the Node to Server, but after that it either errors, or does not do...
3
by: danfolkes | last post by:
Why does the message send only once? The node sends once, then fails after that. <code> import socket import thread import time def Node(nodeAddress):
3
by: Giampaolo Rodola' | last post by:
Hi, I'd like to know if there's a way to determine which is the best buffer size to use when you have to send() and recv() some data over the network. I have an FTP server application which, on...
0
by: Xionbox | last post by:
Hello everybody, The error I have seems very easy to solve, but for some odd reason I can't seem to solve it. Anyways, here's my "setup". I created a server running on localhost:1200 (telnet...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.