예제 #1
0
  // Cleanup for disconnect
  private static void cleanUp() {
    try {
      if (hostServer != null) {
        hostServer.close();
        hostServer = null;
      }
    } catch (IOException e) {
      hostServer = null;
    }

    try {
      if (socket != null) {
        socket.close();
        socket = null;
      }
    } catch (IOException e) {
      socket = null;
    }

    try {
      if (in != null) {
        in.close();
        in = null;
      }
    } catch (IOException e) {
      in = null;
    }

    if (out != null) {
      out.close();
      out = null;
    }
  }
 /** Stop talking to the server */
 public void stop() {
   if (socket != null) {
     // Close all the streams and socket
     if (out != null) {
       try {
         out.close();
       } catch (IOException ioe) {
       }
       out = null;
     }
     if (in != null) {
       try {
         in.close();
       } catch (IOException ioe) {
       }
       in = null;
     }
     if (socket != null) {
       try {
         socket.close();
       } catch (IOException ioe) {
       }
       socket = null;
     }
   } else {
     // Already stopped
   }
   // Make sure the right buttons are enabled
   start_button.setEnabled(true);
   stop_button.setEnabled(false);
   setStatus(STATUS_STOPPED);
 }
예제 #3
0
 public void disconnect() {
   try {
     dos.close();
     s.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
예제 #4
0
 public void disconnect() {
   try {
     dos.close();
     s.close();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
예제 #5
0
 public void dispose() {
   try {
     if (s != null) s.close();
     cClient.remove(this);
     ta.append("A client out! \n");
     ta.append("CLIENT-COUNT: " + cClient.size() + "\n\n");
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
예제 #6
0
 // Close crap after chatting
 private void closeCrap() {
   showMessage("\n Closing connection... \n ");
   ableToType(false);
   try {
     output.close();
     input.close();
     connection.close();
   } catch (IOException ioException) {
     ioException.printStackTrace();
   }
 }
예제 #7
0
 // Close socket and IO streams, change appearance/functionality of some components
 private void closeAll() throws IOException {
   displayArea.append("\nConnection closing");
   output.close();
   input.close();
   connection.close();
   // We are no longer connected
   connection = null;
   // Change components
   serverField.setEditable(true);
   connectButton.setLabel("Connect to server above");
   enterField.setEnabled(false);
 }
예제 #8
0
 public void disconnect() {
   int cmdID = commID++;
   this.connected = false;
   try {
     out.println(cmdID + ";logout");
     out.flush();
     in.close();
     out.close();
     socket.close();
   } catch (IOException ex) {
     System.err.println("Server stop failed.");
   }
 }
예제 #9
0
 public void run() {
   String texto = "";
   while (repetir) {
     try {
       Empleados e = (Empleados) inObjeto.readObject();
       textarea1.setText("");
       textarea1.setForeground(Color.blue);
       if (e == null) {
         textarea1.setForeground(Color.red);
         PintaMensaje("<<EL EMPLEADO NO EXISTE>>");
       } else {
         texto =
             "Empleado: "
                 + e.getEmpNo()
                 + "\n   "
                 + "Oficio: "
                 + e.getOficio()
                 + "\tApellido: "
                 + e.getApellido()
                 + "\n    "
                 + "Comisión: "
                 + e.getComision()
                 + "\tDirección: "
                 + e.getDir()
                 + "\n    "
                 + "Alta: "
                 + e.getFechaAlt()
                 + "\tSalario: "
                 + e.getSalario()
                 + "\n    "
                 + "Departamento: "
                 + e.getDepartamentos().getDnombre();
         textarea1.append(texto);
       }
     } catch (SocketException s) {
       repetir = false;
     } catch (IOException e) {
       e.printStackTrace();
       repetir = false;
     } catch (ClassNotFoundException e) {
       e.printStackTrace();
       repetir = false;
     }
   }
   try {
     socket.close();
     System.exit(0);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
예제 #10
0
  public Duder(String args[]) {

    getConnected(args);

    play();

    try {
      sin.close();
      sout.close();
      s.close();
    } catch (IOException e) {
      System.out.println(e);
    }
  }
예제 #11
0
  public void nick_name(String msg) {
    try {
      String name = msg.substring(13);
      this.setName(name);
      Vector v = father.onlineList;
      boolean isRepeatedName = false;
      int size = v.size();
      for (int i = 0; i < size; i++) {
        ServerAgentThread tempSat = (ServerAgentThread) v.get(i);
        if (tempSat.getName().equals(name)) {
          isRepeatedName = true;
          break;
        }
      }
      if (isRepeatedName == true) {
        dout.writeUTF("<#NAME_REPEATED#>");
        din.close();
        dout.close();
        sc.close();
        flag = false;
      } else {
        v.add(this);
        father.refreshList();
        String nickListMsg = "";
        StringBuilder nickListMsgSb = new StringBuilder();
        size = v.size();
        for (int i = 0; i < size; i++) {
          ServerAgentThread tempSat = (ServerAgentThread) v.get(i);
          nickListMsgSb.append("!");
          nickListMsgSb.append(tempSat.getName());
        }
        nickListMsgSb.append("<#NICK_LIST#>");
        nickListMsg = nickListMsgSb.toString();
        Vector tempv = father.onlineList;
        size = tempv.size();
        for (int i = 0; i < size; i++) {
          ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i);
          tempSat.dout.writeUTF(nickListMsg);
          if (tempSat != this) {
            tempSat.dout.writeUTF("<#MSG#>" + this.getName() + "is now online....");
          }
        }
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
예제 #12
0
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == boton) {
      try {
        salida.writeUTF(empconsultar.getText());
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }

    if (e.getSource() == desconectar) {
      try {
        socket.close();
      } catch (IOException e1) {
        e1.printStackTrace();
      }
      System.exit(0);
    }
  }
예제 #13
0
  public ReciveFile() {
    super("파일전송");
    setLayout(null);
    lbl = new Label("파일 전송을 기다립니다.");
    lbl.setBounds(10, 30, 230, 20);
    lbl.setBackground(Color.gray);
    lbl.setForeground(Color.white);
    add(lbl);
    txt = new TextArea("", 0, 0, TextArea.SCROLLBARS_BOTH);
    txt.setBounds(10, 60, 230, 100);
    txt.setEditable(false);
    add(txt);
    btn = new Button("닫기");
    btn.setBounds(105, 170, 40, 20);
    btn.setVisible(false);
    btn.addActionListener(this);
    add(btn);
    addWindowListener(new WinListener());
    setSize(250, 200);
    show();

    try {
      ServerSocket socket = new ServerSocket(port);
      Socket sock = null;
      FileThread client = null;
      try {
        sock = socket.accept();
        client = new FileThread(this, sock);
        client.start();
      } catch (IOException e) {
        System.out.println(e);
        try {
          if (sock != null) sock.close();
        } catch (IOException e1) {
          System.out.println(e1);
        } finally {
          sock = null;
        }
      }
    } catch (IOException e) {
    }
  }
예제 #14
0
  // {{{ handleClient() method
  private boolean handleClient(final Socket client, DataInputStream in) throws Exception {
    int key = in.readInt();
    if (key != authKey) {
      Log.log(
          Log.ERROR,
          this,
          client + ": wrong" + " authorization key (got " + key + ", expected " + authKey + ")");
      in.close();
      client.close();

      return false;
    } else {
      // Reset the timeout
      client.setSoTimeout(0);

      Log.log(Log.DEBUG, this, client + ": authenticated" + " successfully");

      final String script = in.readUTF();
      Log.log(Log.DEBUG, this, script);

      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              try {
                NameSpace ns = new NameSpace(BeanShell.getNameSpace(), "EditServer namespace");
                ns.setVariable("socket", client);
                BeanShell.eval(null, ns, script);
              } catch (org.gjt.sp.jedit.bsh.UtilEvalError e) {
                Log.log(Log.ERROR, this, e);
              } finally {
                try {
                  BeanShell.getNameSpace().setVariable("socket", null);
                } catch (org.gjt.sp.jedit.bsh.UtilEvalError e) {
                  Log.log(Log.ERROR, this, e);
                }
              }
            }
          });

      return true;
    }
  } // }}}
예제 #15
0
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == ld.st) // 0.로딩화면에서 Enter버튼 클릭
    {
      System.out.println("할리갈리 온라인 안쪽으로 접근중...");
      card.show(getContentPane(), "LOG");
    } else if (e.getSource() == login.bt1) // 1.팝업창으로 회원가입창 띄우기
    {
      mID.setBounds(470, 310, 340, 420);
      mID.setVisible(true);
    } else if (e.getSource() == login.bt2) // 2.로그인버튼 누르기
    {
      ld.clip.stop();
      wr.clip.play();
      id = login.tf.getText().trim(); // ID입력안했을때
      if (id.length() < 1) {
        JOptionPane.showMessageDialog(this, "ID를 입력하세요");
        login.tf.requestFocus();
        return;
      }
      String pass = new String(login.pf.getPassword()); // PWD입력안했을때
      if (pass.length() < 1) {
        JOptionPane.showMessageDialog(this, "Password를 입력하세요");
        login.pf.requestFocus();
        return;
      }

      connection(); // 모두 정확히 처리했으면, connection()메소드로 이동!!

      try {
        out.write(
            (Function.LOGIN
                    + "|"
                    + id
                    + "|" // 로그인버튼 눌러서 server에게 요청
                    + pass
                    + "\n")
                .getBytes());
      } catch (Exception ex) {
      }
    } else if (e.getSource() == wr.tf || e.getSource() == wr.b1) // 3.waitroom에서 채팅입력할 때
    {
      String data = wr.tf.getText(); // 입력한 값 가져오기
      if (data.length() < 1) return;
      try {
        out.write((Function.WAITCHAT1 + "|" + data + "\n").getBytes()); // 채팅전송을 server에게 요청
      } catch (Exception ex) {
      }
      wr.tf.setText("");
    } else if (e.getSource() == gw.tf || e.getSource() == gw.b1) // 4.gameWindow에서 채팅입력할 때
    {
      String data = gw.tf.getText(); // 입력한 값 가져오기
      if (data.length() < 1) return;
      try {
        out.write((Function.ROOMCHAT + "|" + data + "\n").getBytes()); // 채팅전송을 server에게
      } catch (Exception ex) {
      }
      gw.tf.setText("");
    } else if (e.getSource() == wr.b2) // 5.방만들기창
    {
      mr.tf.setText(""); // 방만들기 초기화
      mr.pf.setText("");
      mr.rb1.setSelected(true);
      mr.setBounds(500, 300, 260, 290);
      mr.setVisible(true);
    } else if (e.getSource() == wr.b3) // 6.방들어가기 버튼처리 /////////////////////////////////
    {
      wr.clip.stop();
      gw.clip.play();
      System.out.println("방유저리스트수: " + gw.model1.getRowCount());
      for (int i = 0; i < gw.model1.getRowCount(); i++) {
        System.out.println("방유저리스트삭제");
        gw.model1.removeRow(i); // 추가
      }
      // gw.model1.removeRow(0); //추가
      if (rowNum >= 0) {
        try {
          gw.ta.setText("");
          out.write((Function.JOINROOM + "|" + rowNum + "\n").getBytes());
        } catch (Exception e2) {
        }
      }
    } else if (e.getSource() == mr.b1) // 6.방만들기창에서 확인 눌렀을때//////////////////////////////
    {
      wr.clip.stop();
      gw.clip.play();
      gw.clip.loop();

      String subject = mr.tf.getText().trim(); // 방이름 입력 안했을때
      if (subject.length() < 1) {
        JOptionPane.showMessageDialog(this, "방이름을 입력하세요");
        mr.tf.requestFocus();
        return;
      }

      if (mr.rb2.isSelected()) { // 비공개 버튼 눌렀을 때
        String pw = new String(mr.pf.getPassword());
        if (pw.length() < 1) {
          JOptionPane.showMessageDialog(this, "비밀번호를 입력하세요");
          mr.pf.requestFocus();
          return;
        }
      }

      mr.dispose();
      /*System.out.println("방유저리스트수: "+gw.model1.getRowCount());
          for(int i=0;i<gw.model1.getRowCount();i++)
      {
          	  System.out.println("방유저리스트삭제");
       gw.model1.removeRow(i); //추가
      }*/
      try {
        String roomType = ""; // 1.공개or비공개 저장
        if (mr.rb1.isSelected()) {
          roomType = mr.rb1.getText();
        } // 공개
        else if (mr.rb2.isSelected()) {
          roomType = mr.rb2.getText();
        } // 비공개
        String roomName = mr.tf.getText(); // 2.방이름
        String capaNum = mr.box.getSelectedItem().toString(); // 3.최대인원수
        out.write(
            (Function.MAKEROOM + "|" + roomType + "|" + roomName + "|" + capaNum + "\n")
                .getBytes());
        // 공개여부,방이름,최대인원 넘겨줌

      } catch (Exception ex) {
      }

    } else if (e.getSource() == wr.b8) // 도움말 버튼처리
    {
      help.setVisible(true);
      repaint();
    } else if (e.getSource() == wr.b9) // 게임종료 버튼처리
    {
      /*서버로 종료 메시지 전송후 프로그램 종료*/
      try {
        out.write((Function.CLIENTEXIT + "|\n").getBytes());

      } catch (Exception e2) {
      }

      try {
        s.close(); // 소켓해제
      } catch (IOException e1) {
        e1.printStackTrace();
      }
      System.exit(0);
    } else if (e.getSource() == mID.b1) // 가입완료버튼
    {
      String name = mID.tf1.getText().trim();
      String id = mID.tf2.getText().trim();
      String pass1 = new String(mID.pf1.getPassword());
      String pass2 = new String(mID.pf2.getPassword());
      if (name.length() < 1) {
        JOptionPane.showMessageDialog(this, "이름을 입력하세요");
        mID.tf1.requestFocus();
        return;
      } else if (id.length() < 1) {
        JOptionPane.showMessageDialog(this, "ID를 입력하세요");
        mID.tf2.requestFocus();
        return;
      } else if (mID.ck == false) {
        JOptionPane.showMessageDialog(this, "ID 중복체크 하시오");
        mID.tf2.requestFocus();
        return;
      } else if (pass1.length() < 1) {
        JOptionPane.showMessageDialog(this, "비밀번호를 입력하세요");
        mID.pf1.requestFocus();
        return;
      } else if (pass2.length() < 1) {
        JOptionPane.showMessageDialog(this, "비밀번호 확인을 입력하세요");
        mID.pf2.requestFocus();
        return;
      } else if (!(pass1.equals(pass2))) {
        JOptionPane.showMessageDialog(this, "비밀번호가 동일하지 않습니다");
        mID.pf1.requestFocus();
        return;
      }
      try {
        out.write((Function.SUCCESSJOIN + "|" + name + "|" + id + "|" + pass1 + "\n").getBytes());
      } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
      JOptionPane.showMessageDialog(this, "회원가입완료");
      mID.dispose();
    } else if (e.getSource() == mID.b2) {
      mID.tf1.setText("");
      mID.tf2.setText("");
      mID.pf1.setText("");
      mID.pf2.setText("");
      mID.dispose();
    } else if (e.getSource() == mID.b3) // ID중복체크
    {
      String id = mID.tf2.getText().trim();
      if (id.length() < 1) {
        JOptionPane.showMessageDialog(this, "ID를 입력하세요");
        mID.tf2.requestFocus();
        return;
      }

      if (mID.num == 0) // 한번도 소켓을 연결하지 않았다면
      {
        System.out.println("연결시도");
        connection();
        mID.num++;
      }

      System.out.println("ID중복체크");
      try {
        System.out.println(id);
        out.write((Function.IDCHECK + "|" + id + "\n").getBytes()); // ID중복체크를 server에게 요청
      } catch (Exception ex) {
      }
    } else if (e.getSource() == gw.b4) { // GameWindow에서 준비버튼 눌렀을 때

      gw.clip.stop();
      gw.clip3.play();
      try {
        out.write((Function.ROOMREADY + "|" + "\n").getBytes());
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    } else if (e.getSource() == gw.b5) { // GameWindow에서 시작버튼 눌렀을 때
      try {
        out.write((Function.ROOMSTART + "|" + "\n").getBytes());
        gw.b5.setEnabled(false);
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    } else if (e.getSource() == gw.b6) // GameWindow에서 나가기 눌렀을 때
    {
      gw.clip.stop();
      gw.clip2.play();
      wr.clip.play();
      System.out.println("방나가기 버튼 Click");
      System.out.println("방유저리스트수: " + gw.model1.getRowCount());
      // int tmp=gw.model1.getRowCount();
      /*for(int i=0;i<gw.model1.getRowCount();i++)
      {
      	  gw.model1.removeRow(i); //추가
      }*/
      // gw.model1.
      wr.ta.setText(""); // 수정
      gw.b4.setEnabled(true);
      try {
        out.write((Function.EXITROOM + "|" + "\n").getBytes());
      } catch (Exception ex) {
      }
    } else if (e.getSource() == gw.cardOpen) // 카드뒤집기 눌렀을 때!!!
    {
      gw.clip4.play(); // 카드 넘기는 소리
      gw.cardOpen.setBorderPainted(false);
      gw.cardOpen.setContentAreaFilled(false);
      gw.cardOpen.setEnabled(false);
      try {
        out.write((Function.CARDOPEN + "|" + id + "\n").getBytes());
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    } else if (e.getSource() == gw.bell) // 종치기 버튼
    {
      gw.clip1.play(); // 종치는소리
      try {
        out.write((Function.BELL + "|" + id + "\n").getBytes());
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
  }
예제 #16
0
 // サーバーから切断する
 public void close() throws IOException {
   sendMessage("close");
   socket.close();
 }