Package pachalen.socketconnection.client

Source Code of pachalen.socketconnection.client.ClientRunState

package pachalen.socketconnection.client;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

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

public class ClientRunState implements ClientState {
  private JavaDebugTool D;
  SocketClient clt = SocketClient.INST;
 
  public ClientRunState(){
    try{
      D = new JavaDebugTool("ClientWaitState");
    }catch(Exception e){}
  }
 
  @Override
  public void setUp() {
    D.Error("Ŭ���̾�Ʈ�� �۵����� ���� ������ �� �����ϴ�");
  }

  @Override
  public void setDown() {
    try {
      clt.sock.close();
      clt.currentState = clt.clientWaitState;
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

  @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() {
    try {
      clt.writer.writeObject(new SocketMessage(SocketMessage.MsgType.LOGIN,clt.user,"",null));
      clt.writer.flush();
      D.Debug("'"+clt.user+"'�� ���������� �α����� �õ��մϴ�.");
    } catch (IOException e) {
      D.Error("�α��� �� �����߻�");
    }
  }

  @Override
  public void logout() {
    try{
      clt.writer.writeObject(new SocketMessage(SocketMessage.MsgType.LOGOUT,clt.user,"",null));
      clt.writer.flush();
    }catch(IOException e){
      D.Error("�α׾ƿ� �� �����߻�");
    }
   
  }

  @Override
  public void act(SocketMessage message) {
    if(clt.MessageTypes.containsKey(message.getDetailMsgType())){
      clt.MessageTypes.get(message.getDetailMsgType()).act(message);
    }
  }

  @Override
  public ArrayList<String> makeUserList(String listSource) {
    ArrayList<String> aryUserList = new ArrayList<String>();
    String temp[] = listSource.split("/");
    for(String s : temp){
      aryUserList.add(s);
    }
    Collections.sort(aryUserList);
    return aryUserList;
  }
}
TOP

Related Classes of pachalen.socketconnection.client.ClientRunState

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.