I am writing a program and it needs to get input from a socket and if no input continue to run and calculate and yet still be able to get input. The only way (I think) I know how to do this is with the POLLIN function? Is there a better way to do this? Or is there a way to do it with threading.. fork()?
thnx
Sockets
Started by
Guest_mastersjw_*
, Jan 26 2007 02:12 AM
2 replies to this topic
#1
Guest_mastersjw_*
Posted 26 January 2007 - 02:12 AM
Guest_mastersjw_*
|
|
|
#2
Posted 27 January 2007 - 08:18 AM
I don't know Java very well but maybe this code will help you, it reads input and puts output via socket continuously for a client/server IM:
while ((inputLine = in.readLine()) != null) {
outputLine = kkp.processInput(inputLine);
out.println(outputLine);
if outputLine.equals("Bye."))
break;
}
Void
#3
Guest_mastersjw_*
Posted 29 January 2007 - 12:42 AM
Guest_mastersjw_*
From just doing some looking around I think the best way to do it is with threads. Its actually really simple with java. The project involves a simulation running in the background while a client connects and gives the simulation commands. So one thread will handle the simulation and another one will wait for input from the socket. the UNIX/LINUX command of fork() is not necessary since java has its own support for threads.
Thnx
Thnx


Sign In
Create Account

Back to top










