Package pachalen.socketconnection.client

Source Code of pachalen.socketconnection.client.ClientWaitState$IncomingReader

package pachalen.socketconnection.client;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;

import pachalen.javadebug.JavaDebugTool;
import pachalen.socketconnection.MessageType;
import pachalen.socketconnection.SocketAct;
import pachalen.socketconnection.SocketMessage;

public class ClientWaitState implements ClientState {
  private JavaDebugTool D;
  SocketClient clt = SocketClient.INST;
 
  public ClientWaitState(){
    try{
      D = new JavaDebugTool("ClientWaitState");
    }catch(Exception e){}
  }
 
  private class IncomingReader implements Runnable{
    public void run() {
        SocketMessage message;
        SocketMessage.MsgType type;
        try{
          while(true){
            message = (SocketMessage)clt.reader.readObject();
            D.Debug(message.getSender() + "���� ���� �޼��� ���� - " + message);
            type = message.getMsgType();
            switch(type){
            case LOGIN_FAILURE:
              D.Error("�ߺ��� �����̸� �Դϴ�.");
              break;
            case LOGIN_LIST:
              clt.lstUpdate.listUpdate(clt.currentState.makeUserList(message.getSender()));
              break;
            case SERVER_MSG:
              clt.currentState.act(message);
              break;
            default:
              D.Error("�������� �� �� ���� �޼��� ����");
              break;
            }
          }
        }
        catch(Exception e){
          D.Error("�������� �޼��� �޴� �� ���� �߻�");
          e.printStackTrace();
        }
    }
  }
 
  @Override
  public void setUp() {
    try {
      clt.sock = new Socket(clt.ip, clt.socket);
      clt.reader = new ObjectInputStream(clt.sock.getInputStream());
      clt.writer = new ObjectOutputStream(clt.sock.getOutputStream());
      clt.readerThread = new Thread(new IncomingReader());
      clt.readerThread.start();
      clt.currentState = clt.clientRunState; // ���º�ȯ
      D.Debug("Ŭ���̾�Ʈ�� ������ ���ӵǾ����ϴ�. IP : "+clt.ip+" Socket : "+clt.socket);
    } catch (Exception e) {
      D.Error("���� �����߿� �����߻�, ������ �����մϴ�.");
    }
  }

  @Override
  public void setDown() {
    D.Error("Ŭ���̾�Ʈ�� ������� ���� ���� �� �����ϴ�.");
  }

  @Override
  public void addAct(MessageType msg, SocketAct act) {
    clt.MessageTypes.put(msg, act);
    D.Debug(msg + "�� �ش��ϴ� �ൿ�� Ŭ���̾�Ʈ�� �Ҵ�Ǿ����ϴ�. �ൿ �� : " + clt.MessageTypes.size());
  }

  @Override
  public void removeAct(MessageType msg) {
    clt.MessageTypes.remove(msg);
    D.Debug(msg + "�� �ش��ϴ� �ൿ�� Ŭ���̾�Ʈ���� ���ŵǾ����ϴ�. �ൿ �� : " + clt.MessageTypes.size());
  }

  @Override
  public void login() {
    D.Error("Ŭ���̾�Ʈ�� ������� ���� �α��� �� �� �����ϴ�.");
  }

  @Override
  public void logout() {
    D.Error("Ŭ���̾�Ʈ�� ������� ���� �α׾ƿ� �� �� �����ϴ�.");
  }

  @Override
  public void act(SocketMessage message) {
    D.Error("Ŭ���̾�Ʈ�� ������� ���� �۵��� �� �����ϴ�.");
  }

  @Override
  public ArrayList<String> makeUserList(String listSource) {
    D.Error("Ŭ���̾�Ʈ�� ������� ���� ������ �� �����ϴ�.");
    return null;
  }
}
TOP

Related Classes of pachalen.socketconnection.client.ClientWaitState$IncomingReader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.