Article View: borland.public.cppbuilder.internet.socket
Article #3813Re: sendto to same destination more times after eachother fails.?
From: Remy Lebeau (TeamB)
Date: Fri, 29 Apr 2005 23:08
Date: Fri, 29 Apr 2005 23:08
51 lines
3128 bytes
3128 bytes
"longshot" <a@ladidadi.nl> wrote in message news:4272a30c@newsgroups.borland.com... > I try to send information from one bb app to another using : > > int r = sendto(SOCKET,bytes,length,0,(sockaddr *)&to,sizeof(sockaddr_in)); How many bytes are you actually sending each time you call sendto()? > I send 3 packets after eachother. > The first packet is received corectly, the second one > is 370 bytes instead of the 20 bytes send. > The third one isn't received at all. Did you actually send 370+ bytes to begin with? If so, then what you describe is perfectly normal socket behavior. Multiple packets can (and usually are) merged together during transmission, and a single packet can (and usually is) split into multiple transmissions. Your code has to be able to handle all three situations (receiving individual packets as-is, receiving merged packets , and receiving split packets). > If i place a Sleep(200); between the send calls, i do receive > the packets correctly. That just goes to show that your packets are likely being merged together and your receiving code is not set up to handle that situation. > Is anyone familliar with this problem and knows a better solution > than Sleep(200); ??? Re-design your code to handle the packets properly in the first place. The best way is to continuously place everything you receive into a buffer, and then process your packets from the buffer only when they are completely available. How you determine when a given packet is completely available depends on the actual layout of your packets. Unless all of your packets are the same fixed length each time, then you have a couple of options: 1) the best thing to do is to place a fixed-length header at the beginning of each packet which includes a field to specify the size of the remaining variable-length packet data. You can then look at the packet header to know if the remaining packet data is available yet. 2) place a unique delimiter between your packets, using a single byte or a byte sequence that is guaranteed to never appear inside your packet data. Then you can look for that delimiter when checking your buffer for complete packets. Gambit
Technical Details
Message-ID:
<4272bde4$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4272a30c@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,56c67ad4148993cd X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <4272a30c@newsgroups.borland.com> Subject: Re: sendto to same destination more times after eachother fails.? Date: Fri, 29 Apr 2005 16:08:43 -0700 Lines: 53 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <4272bde4$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1114815972 68.69.17.41 (29 Apr 2005 16:06:12 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail