It's not a secret anymore!
The moose likes Sockets and Internet Protocols and the fly likes reading from TCP socket problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "reading from TCP socket problem" Watch "reading from TCP socket problem" New topic
Author

reading from TCP socket problem

Michal Bury
Greenhorn

Joined: Sep 13, 2006
Posts: 6
Hi I am new with TCP socket's.
My problem is as follows:
I tried a sample program that listen as a server on desired port, read data from socket and send the data back (see code). But nothing happens. In network monitor I can see that the data from client are comming but nothing is sended back.
Can anybody help to understand where is my problem.

thanks

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8265

The code looks fine to me. What do you mean by "nothing happens"?
How about putting in additional System.out.println() messages, for example immediately before and after echoServer.accept() and after the while(true) loop. That will help you establish if the code is doing what you think it is doing.
One thing I notice is that this code will only handle one client. Ever. So if you hooked up once and didn't restart the server, your next client will not be serviced (though I'd expect the while(true) to exit with an exception when the first client exited. . .)


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Michal Bury
Greenhorn

Joined: Sep 13, 2006
Posts: 6
Ok. I found the problem. It was on the Client side. It sended data without
"end of line", therefore I can not use readln() but only read.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: reading from TCP socket problem
 
Similar Threads
simple socket question
NIO non-blocking newbie
Exception in Socket Server
simple socket programming
Address already used problem in Java Socket application