We used threads to run the server based part (originally it was a stand alone game and then we networked it, so we tried to keep most of the original structure intact). Here's the run function:
| public void run() | 
| { | 
| try | 
| { | 
| //Set the port number | 
| int port = 1352; | 
| //Establish the listen socket. | 
| ServerSocket welcomeSocket = new ServerSocket(port); | 
| InetAddress addr = InetAddress.getLocalHost(); | 
| String ip = addr.getHostAddress(); | 
| mMessage.setText("   Server IP Address: " + ip); | 
| //Process service requests in an infinite loop | 
| while (true) | 
| { | 
| //Listen for a TCP connection request | 
| Socket connectionSocket = welcomeSocket.accept(); | 
| // Construct an object to process the request. | 
| BingoHandler request = new BingoHandler(connectionSocket); | 
| // Create a new thread to process the request. | 
| Thread thread = new Thread(request); | 
| // Start the thread. | 
| thread.start(); | 
| } | 
| } | 
| catch (Exception e) | 
| { | 
| } | 
| } | 
Some simple stuff, but we were really proud to get it working.
//END OF LINE
 
No comments:
Post a Comment