Hello,
This is my first run at a client/server application.
Basically I start the server use the ServerSocket and bind it to the port. Next I listen for the client connection and upon receiving it I start a new thread which in turns allows for multiple clients to log on.
This works fine and dandy. What I want to do is to be able to return something from that client thread, for instance, maybe the client gave authorization to shutdown the server. How would I go about passing a string or other object back from the thread? Do I need to create some sort of listener?
Thanks,
Ron
typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
This is my first run at a client/server application.
Basically I start the server use the ServerSocket and bind it to the port. Next I listen for the client connection and upon receiving it I start a new thread which in turns allows for multiple clients to log on.
Code:
[blue]
public static void main(String[] args) throws IOException
{
try
{
StartDate = new Date(System.currentTimeMillis());
System.out.println("Binding...");
serverSocket = new ServerSocket(SERVERPORT);
System.out.println("Bound! Waiting for connection....");
}
catch (IOException e)
{
System.out.println("Unable to bind! \n" +e.toString());
}
while(ClientCount<4)
{
try
{
clientSocket = serverSocket.accept();
ClientCount++;
new Client(clientSocket,StartDate).start();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
[/blue]
This works fine and dandy. What I want to do is to be able to return something from that client thread, for instance, maybe the client gave authorization to shutdown the server. How would I go about passing a string or other object back from the thread? Do I need to create some sort of listener?
Thanks,
Ron
typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;