Jump to content

Sockets

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Guest_mastersjw_*

Guest_mastersjw_*
  • Guests
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

#2
Void

Void

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 411 posts
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_*

Guest_mastersjw_*
  • Guests
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