jpaladin
-Interested User-
Posts: 2
Joined: Jan 30, 2008
|
Posted: Feb 2, 2008 09:36 AM
Msg. 1 of 2
I am new to sockets, and figuring out this sample application code :
while (true ) {
line = in.readLine();
sout.write(line+"\r\n"); sout.flush();
if (line.trim().equals("x") ) {break;}
}
So, why does in.readLine() block, and what could it possibly be waiting for ? Setting a break point after in.readLine() it never hits. I guess socket code blocks by default when you tell it to read, and it is empty ?
I see that "in" is a System.in socket, so I guess it is some kind of global server socket.
When it gets something, it is reflected to the IQFeed socked that I watch for my data, so I would like to know what I might have to deal with while watching the data.
if an "x" arrives my whole feed is going to be shutdown.
So, I would like to better understand this code.
Joe paladin
|
JDonovan
-Interested User-
Posts: 24
Joined: Feb 11, 2007
|
Posted: Feb 5, 2008 07:40 AM
Msg. 2 of 2
Windows sockets block by default....it's waiting for data to arrive. You can easilly set the sockets to non-blocking, suggest digging into some socket documentation/reading if you want to go much further.
- Jeff
|