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 more data, and will behave as if EOF was reached on the socket.
The server *is* returning data. On windows (reading with Java), the
data is returned, but there are a bunch of NULs in the output. I have
not been able to find any strange characters returned by the server
using a logging tcp proxy called ProxyView, however, so that might be a
bug in the Windows version, or possibly a bug on the part of the test
program I wrote.
At any rate, the server interoperates as expected with every news reader
I've tried, including Netscape and KNode, so I am a bit perplexed why
Java on Linux is have trouble reading from the socket. Reproduction
should be easy: just open a socket to free.teranews.net on port 119,
write "list", and read all data until EOF. You should get a list of
newsgroups if it work, or, if it doesn't, you'll get the Welcome message
and then EOF.
Has anyone seen this behaviour before. Any workarounds? I've tried
this with both JDK1.4 and JDK1.5 (beta), and neither work. If you do
get it to work, would you please post the details of your setup --
version of Linux, JDK, etc.?
Thanks,
--Nathan Davis 7 8036
On Fri, 11 Jun 2004 01:03:45 GMT, Nathan Davis wrote: 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 more data, and will behave as if EOF was reached on the socket.
From the failing machine, try connecting to the server with telnet:
$ telnet free.teranews.com 119
Now issue the list command.
Does it work? If not, this isn't a java issue.
If so, there is likely a problem with the code you forgot to post.
I'm guessing there is a problem with the mechanism you use to read
from the server. More specifically I suspect that you are using
InputStream.available() or InputStreamReader.ready() in your read
loop. If that's the case: don't.
/gordon
--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Thanks for the response. Yes, telnet'ing to the server and issuing the
list command works. As far as the code goes, no I'm not using
available() or ready(). In a nutshell, here's a version of the code
that fails:
int c = input.read();
while(c != -1){ //read until stream returns "EOF"
c = input.read();
}
Thanks,
--Nathan Davis
Gordon Beaton wrote: On Fri, 11 Jun 2004 01:03:45 GMT, Nathan Davis wrote:
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 more data, and will behave as if EOF was reached on the socket.
From the failing machine, try connecting to the server with telnet:
$ telnet free.teranews.com 119
Now issue the list command.
Does it work? If not, this isn't a java issue.
If so, there is likely a problem with the code you forgot to post.
I'm guessing there is a problem with the mechanism you use to read from the server. More specifically I suspect that you are using InputStream.available() or InputStreamReader.ready() in your read loop. If that's the case: don't.
/gordon
Ok, I've figured this one out. It turns out that the problem is not
with how I *read* from the server, but how I *write* to it. I was using
PrintStream.println(), which only appends a '\n' character to the
string. Apparently, the server was expecting '\r\n', and was closing
the connection when only a '\n' was recieved! I believe the different
behaviour seen under windows in due to the fact that windows uses '\r\n'
as the newline seperator, whereas unix uses only '\n'. Therefore, I
believe you would see the same behaviour with any unix-like system.
Wow! What a lot of head-banging this turned out to be!
--Nathan Davis
Gordon Beaton wrote: On Fri, 11 Jun 2004 01:03:45 GMT, Nathan Davis wrote:
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 more data, and will behave as if EOF was reached on the socket.
From the failing machine, try connecting to the server with telnet:
$ telnet free.teranews.com 119
Now issue the list command.
Does it work? If not, this isn't a java issue.
If so, there is likely a problem with the code you forgot to post.
I'm guessing there is a problem with the mechanism you use to read from the server. More specifically I suspect that you are using InputStream.available() or InputStreamReader.ready() in your read loop. If that's the case: don't.
/gordon
Congrats, you've reimplimented FTP. Yeah, yeah, I just couldn't resist.
Nathan Davis wrote: Ok, I've figured this one out. It turns out that the problem is not with how I *read* from the server, but how I *write* to it. I was using PrintStream.println(), which only appends a '\n' character to the string. Apparently, the server was expecting '\r\n', and was closing the connection when only a '\n' was recieved! I believe the different behaviour seen under windows in due to the fact that windows uses '\r\n' as the newline seperator, whereas unix uses only '\n'. Therefore, I believe you would see the same behaviour with any unix-like system.
Wow! What a lot of head-banging this turned out to be!
--Nathan Davis
Gordon Beaton wrote:
On Fri, 11 Jun 2004 01:03:45 GMT, Nathan Davis wrote:
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 more data, and will behave as if EOF was reached on the socket. From the failing machine, try connecting to the server with telnet:
$ telnet free.teranews.com 119
Now issue the list command.
Does it work? If not, this isn't a java issue.
If so, there is likely a problem with the code you forgot to post.
I'm guessing there is a problem with the mechanism you use to read from the server. More specifically I suspect that you are using InputStream.available() or InputStreamReader.ready() in your read loop. If that's the case: don't.
/gordon
On Fri, 11 Jun 2004 21:18:09 GMT, Nathan Davis wrote: Ok, I've figured this one out. It turns out that the problem is not with how I *read* from the server, but how I *write* to it. I was using PrintStream.println(), which only appends a '\n' character to the string. Apparently, the server was expecting '\r\n', and was closing the connection when only a '\n' was recieved! I believe the different behaviour seen under windows in due to the fact that windows uses '\r\n' as the newline seperator, whereas unix uses only '\n'. Therefore, I believe you would see the same behaviour with any unix-like system.
Of course if you're implementing a standard protocol it's always a
good idea to read the relevant RFCs first. Most (possible all) text
based protocols define EOL as a CR LF pair. From rfc977 (NNTP):
2.3. Commands
[...]
Each command line must be terminated by a CR-LF (Carriage Return -
Line Feed) pair.
/gordon
--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
yes, i have seen this type of thing before. the problem is not with
linux, it has to do with a more efficient socket implementation on linux.
i strongly suspect your EOF is as a result of your connection is being
made too fast and either the client or the server is either not ready or
has given up.
to resolve this problem i had to implement a more intelligent connection
scheme where i would try 3 times, pausing 250 ms before each attempt...
it always seemed to get it either on the 1st or 2nd attempt, i never had
any problems after that.
i'll try to dig up the code and post it for you later
- perry
Nathan Davis wrote: 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 more data, and will behave as if EOF was reached on the socket.
The server *is* returning data. On windows (reading with Java), the data is returned, but there are a bunch of NULs in the output. I have not been able to find any strange characters returned by the server using a logging tcp proxy called ProxyView, however, so that might be a bug in the Windows version, or possibly a bug on the part of the test program I wrote.
At any rate, the server interoperates as expected with every news reader I've tried, including Netscape and KNode, so I am a bit perplexed why Java on Linux is have trouble reading from the socket. Reproduction should be easy: just open a socket to free.teranews.net on port 119, write "list", and read all data until EOF. You should get a list of newsgroups if it work, or, if it doesn't, you'll get the Welcome message and then EOF.
Has anyone seen this behaviour before. Any workarounds? I've tried this with both JDK1.4 and JDK1.5 (beta), and neither work. If you do get it to work, would you please post the details of your setup -- version of Linux, JDK, etc.?
Thanks,
--Nathan Davis
i did that one before, most aggravating... in my case i was sending a
"\n\r" rather than a "\r\n", the "\n\r" seemed more logical to me...
took all day and someone looking over my shoulder at the last minute to
get it
- perry
Nathan Davis wrote: Ok, I've figured this one out. It turns out that the problem is not with how I *read* from the server, but how I *write* to it. I was using PrintStream.println(), which only appends a '\n' character to the string. Apparently, the server was expecting '\r\n', and was closing the connection when only a '\n' was recieved! I believe the different behaviour seen under windows in due to the fact that windows uses '\r\n' as the newline seperator, whereas unix uses only '\n'. Therefore, I believe you would see the same behaviour with any unix-like system.
Wow! What a lot of head-banging this turned out to be!
--Nathan Davis
Gordon Beaton wrote:
On Fri, 11 Jun 2004 01:03:45 GMT, Nathan Davis wrote:
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 more data, and will behave as if EOF was reached on the socket. From the failing machine, try connecting to the server with telnet:
$ telnet free.teranews.com 119
Now issue the list command.
Does it work? If not, this isn't a java issue.
If so, there is likely a problem with the code you forgot to post.
I'm guessing there is a problem with the mechanism you use to read from the server. More specifically I suspect that you are using InputStream.available() or InputStreamReader.ready() in your read loop. If that's the case: don't.
/gordon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tim Gosselin |
last post by:
I am writing a tcp tunnel but cannot find a way of detecting when a socket
shuts down its read end without writing to the socket. For testing the
write end of the remote endpoint I just do a:
if...
|
by: Bruce Vander Werf |
last post by:
I am using the asynchronous send/receive methods of the Socket class.
When the remote end closes the socket, the callback for receive is
called and EndReceive returns 0.
Socket.Connected still...
|
by: Nuno Magalhaes |
last post by:
I've got a simple problem I guess. How do I know when a connection is
terminated without losing any data?
I do something like the code below, but sometimes between
socket.Receive and socket.Send...
|
by: David |
last post by:
After programming with Python for a few hours, I've come up with some code:
http://p.shurl.net/3n. However, now I've realised there's a bit of a
problem with the original design.
I have a...
|
by: djc |
last post by:
I read a network programming book (based on framework 1.1) which indicated
that you should 'never' use the RecieveTimeout or the SendTimeout 'socket
options' on TCP sockets or you may loose data. I...
|
by: jnair |
last post by:
When using socket.socket.settimeout we normally only guard against
"socket.timeout" exception.Now the implementation of "settimeout" in
"Python-2.4.3/Modules/socketmodule.c" sets the socket fd to...
|
by: semedao |
last post by:
Hi all,
I view many posts about this issue , the connected property does not tell us the current status of the socket.
based on couple of suggestions of msdn , and some article here , I try to...
|
by: Engineerik |
last post by:
I am trying to create a socket server which will listen for connections from
multiple clients and call subroutines in a Fortran DLL and pass the results
back to the client. The asynchronous socket...
|
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...
|
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...
|
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...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |