473,725 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket reading problem

Hi,

I'm writing an NNTP based program that downloads articles from Usenet.
I've run into a weird problem. It seems as if there is a bug somewhere
that causes certain articles to download incorrectly (just by a byte or
two). It happens to the same articles and about 1 out of 5 have issues. So
everything seems to work ok, but somewhere something causes this weird
behavior.

The code that should work but doesn't (sometimes) downloads an article and
returns it.

Any help would be appreciated.

Matta

- - - - -

string NNTP::net_recv( )
{
int numbytes;
string buffer;
char buf[MAXDATASIZE];

numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0);

if (numbytes < 1) {
return "";
}

buf[numbytes] = '\0';

buffer = buf;
return buffer;
}

extern "C" string NNTP::get_artic le(string msgid)
{
string rdata, sendstr, tmp;
string::size_ty pe pos;

sendstr = "ARTICLE ";
sendstr += msgid;
sendstr += "\r\n";

net_send(sendst r);

rdata = "";
do {
rdata += net_recv();
} while (rdata.substr(r data.length()-5, 5) != "\r\n.\r\n" );

rdata = rdata.substr(0, rdata.length() - 3);

pos = rdata.find("\r\ n\r\n", 0);
rdata = rdata.substr(po s + 4, rdata.length() - (pos + 4));

if (rdata.substr(0 , 2) == "..") {
rdata.erase(0, 1);
}

pos = 0;
while ((pos = rdata.find("\r\ n..", pos)) != string::npos) {
rdata.erase(pos + 2, 1);
}

return rdata;
}
Nov 14 '05 #1
3 1244
Matta <ma***@use.ne t> wrote in
news:pa******** *************** *****@use.net:
I'm writing an NNTP based program that downloads articles from Usenet.
I've run into a weird problem. It seems as if there is a bug somewhere
that causes certain articles to download incorrectly (just by a byte or
two). It happens to the same articles and about 1 out of 5 have issues.
So everything seems to work ok, but somewhere something causes this
weird behavior.

The code that should work but doesn't (sometimes) downloads an article
and returns it.

Any help would be appreciated.

Matta

- - - - -

string NNTP::net_recv( )
{


This is C++ code, not C code, and it's a networking question (probably)
which is outside the scope of comp.lang.c++. Regardless, it's off-topic
here.

--
- Mark ->
--
Nov 14 '05 #2
In article <pa************ *************** *@use.net>,
Matta <ma***@use.ne t> wrote:

Your program appears to be in C++, not C. And you'll probably also
be flamed for asking about code that uses system-specific socket
functions.

As a general debugging hint, I suggest you start by separating out the
socket code from the text processing code. Put one of the failing
articles in a file and read it from there, so you don't have to worry
about the network aspect.

-- Richard
Nov 14 '05 #3
Matta wrote:
.... snip ...
The code that should work but doesn't (sometimes) downloads an
article and returns it.


The code you posted is in C++ (which is OffTopic here) and also
contains calls to non-standard C functions. You need a newsgroup
that deals with your particular system. Here we deal only with
portable C compliant with the ISO standard.

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 14 '05 #4

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

Similar topics

7
8096
by: Nathan Davis | last post by:
Hi, I am having problems reading data from a socket. The problem only occurs while trying to read from one particular server, and does not occur on Windows (as far as I know, this may occur only on Linux). The server is free.teranews.com, and I am trying to connect to the NNTP port (119). To make things even more bizar, I only have trouble when I try to issue the LIST command. After issuing the command, Java will not return any...
1
5430
by: Krzysztof Pa¼ | last post by:
Hi, I want to make simple client in phyton, which would be able to communicate with Java server using SSL sockets. There is the Java clients, which is doing this - so I'm pretty sure, that Java server works OK. I've heard, that P2.3 has SSL support included in himself and also, I was trying P2.2 with pyOpenSSL wrappers and extensions, but unsuccesfuly... So, could you give me a few lines of python code which makes such things:
6
2485
by: Mahesh Devjibhai Dhola [MVP] | last post by:
Hi, Socket class documentation says that it is not thread safe. We understand that if do simultaneous sends on ONE socket then it will be a problem (or simultaneous receive). Can we create TWO threads on OUR OWN such that one will do SEND and one will do RECEIVE using the SAME socket reference? This means that two threads WILL BE in the same SOCKET object - one doing receive and one doing send. We know we can use asynchronous calls on...
9
2480
by: Phil Jenson | last post by:
I am try to evaluate the most efficient method of handling thousands of simultaneous TCP connects each of which remain connected to the server for hours and pass a small amount of data usually once a minute. The data received is logged in a SQL Server database. The only method I have found of reading each socket requires a thread for each connection which blocks waiting for data. This appears to be very inefficient as it will result in...
5
45039
by: Morten | last post by:
How do I detect if a client socket is no longer connected to the listen tcp socket ? I have tried with (just an example): --------------------- Socket tcpSocket; while(tcpSocket.Connected)
1
2781
by: Thomas Lerchner | last post by:
Hi! I have a problem with an UDP socket. I create socket and call BeginReceiveFrom to use the socket async. But the callback methode is being called several times with the same packet from the same sender. It has been confirmed that the data was sent only once. I used a sniffer to debug that. And it does not matter if the data is broadcasted or sent to specific address.
5
11714
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of 1024 with all values set to Null arrive. Other than examine a block of 1024 to see if the entire block is null, is there any other way to determine if , say a chat message "Hi Charlie" has been received completely?
13
2644
by: coloradowebdev | last post by:
i am working on basically a proxy server that handles requests via remoting from clients and executes transactions against a third-party server via TCP. the remoting site works like a champ. my problem is executing the transactions against the remote server and returning the response to the remoting client. i can open the socket fine and, if i am executing one transaction at a time, everything works great. it's when my proxy server...
6
7002
by: Pat B | last post by:
Hi, I'm writing my own implementation of the Gnutella P2P protocol using C#. I have implemented it using BeginReceive and EndReceive calls so as not to block when waiting for data from the supernode. Everything I have written works fine sending and receiving uncompressed data. But now I want to implement compression using the deflate algorithm as the Gnutella protocol accepts: Accept-Encoding: deflate Content-Encoding: deflate in the...
6
3663
by: ahlongxp | last post by:
socket.makefile() may lose data when "connection reset by peer". and socket.recv() will never lose the data. change the "1" to "0" in the client code to see the difference. confirmed on both windows and linux. so I guess there is a problem with makefile(). # Echo server program
0
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9174
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9111
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.