Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // part of GUI code
- start = new JButton ("Start Game Server");
- start.addActionListener (new ActionListener() {
- public void actionPerformed (ActionEvent event) {
- DEFAULT_PORT = Integer.parseInt(port.getText());
- //fgServer.run();
- fgServerFrame = new FishingGameServerFrame();
- //frame.dispose();
- }
- });
- // server code
- public class FishingGameServer {
- private static int DEFAULT_PORT = 0;
- public void run()
- {
- int port = DEFAULT_PORT;
- port = Integer.parseInt(FishingGameConnectServerFrame.portNumber());
- System.out.println("port #: " + port);
- //setup server socket
- ServerSocket reception_socket = null;
- try {
- reception_socket = new ServerSocket (port);
- System.out.println("Started server on port " + port);
- }
- catch (IOException e) {
- //to get text in GUI frame
- System.out.println("Cannot create server");
- System.exit(0);
- }
- for (;;) {
- Socket client_socket = null;
- try {
- client_socket = reception_socket.accept();
- System.out.println("Accepting requests from:" + client_socket.getInetAddress());
- }
- catch (IOException i) {
- System.out.println ("Problem accepting client socket");
- }
- new FishingGameThreadedServer(client_socket);
- }
- }
- public static void main (String[] args) {
- new FishingGameServer().run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement