Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // part of GUI code
  2.  
  3. start = new JButton ("Start Game Server");
  4. start.addActionListener (new ActionListener() {
  5.  
  6. public void actionPerformed (ActionEvent event) {
  7. DEFAULT_PORT = Integer.parseInt(port.getText());
  8. //fgServer.run();
  9. fgServerFrame = new FishingGameServerFrame();
  10. //frame.dispose();
  11. }
  12. });
  13.  
  14. // server code
  15.  
  16. public class FishingGameServer {
  17.  
  18. private static int DEFAULT_PORT = 0;
  19.  
  20. public void run()
  21. {
  22.  
  23. int port = DEFAULT_PORT;
  24.  
  25. port = Integer.parseInt(FishingGameConnectServerFrame.portNumber());
  26. System.out.println("port #: " + port);
  27.  
  28. //setup server socket
  29. ServerSocket reception_socket = null;
  30.  
  31. try {
  32. reception_socket = new ServerSocket (port);
  33. System.out.println("Started server on port " + port);
  34. }
  35. catch (IOException e) {
  36. //to get text in GUI frame
  37. System.out.println("Cannot create server");
  38. System.exit(0);
  39. }
  40.  
  41. for (;;) {
  42. Socket client_socket = null;
  43.  
  44. try {
  45. client_socket = reception_socket.accept();
  46. System.out.println("Accepting requests from:" + client_socket.getInetAddress());
  47. }
  48. catch (IOException i) {
  49. System.out.println ("Problem accepting client socket");
  50. }
  51.  
  52. new FishingGameThreadedServer(client_socket);
  53. }
  54. }
  55.  
  56. public static void main (String[] args) {
  57.  
  58. new FishingGameServer().run();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement