Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Thread, Returning

Status
Not open for further replies.

ronnyjljr

IS-IT--Management
Nov 23, 2003
249
US
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.

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;
 
Well, one way to do this is passing to the thread object a reference from the caller and implement one method the thread object can call to notify events or returning values.

Cheers,

Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top