public INetServer(int maxConnection) { RemotePool.CreateRemotePool(maxConnection); sync_obj = new object(); RemoteClients = new Dictionary <RemoteID, IRemoteClient>(); }
public void OnLeave(T remoteClient) { IRemoteClient client = (IRemoteClient)remoteClient; lock (sync_obj) { RemoteClients.Remove(client.GetRemoteID()); } RemotePool.FreeRemotePool(client.GetRemoteID()); }
/// <summary> /// 클라이언트가 Connect됬을때 가장 먼저 호출해줘야 함 /// </summary> /// <param name="session"></param> /// <returns></returns> public RemoteID OnConnect(ref T session) { RemoteID remote = RemotePool.GetRemotePool(); if (remote == RemoteID.Remote_None) { if (message_handler != null) { message_handler(MsgType.Critical, "remotePool Empty!"); } } lock (sync_obj) { if (RemoteClients.ContainsKey(remote)) { if (message_handler != null) { message_handler(MsgType.Warning, "remote key 중복되어 반복루프시작함... (멀티스레드 서버에서 close된상태에서 남은recv처리가 존재할경우 발생될수있음)"); } while (true) { RemotePool.FreeRemotePool(remote); // 기존 중복된것을 사용안했으니 바로 반환한다음.. remote = RemotePool.GetRemotePool(); // 다시 하나 가져오고.. if (RemoteClients.ContainsKey(remote) == false) { break; } } } RemoteClients.Add(remote, (IRemoteClient)session); } // 내부패킷 보내기 CMessage sMsg = new CMessage(); CPackOption sendOption = CPackOption.Basic; sMsg.WriteStart(PacketType.PacketType_Internal, sendOption); Marshaler.Write(sMsg, PackInternal.ePID_SC_Remote); Marshaler.Write(sMsg, remote); SendToClient(remote, (IRemoteClient)session, sMsg, sendOption); // remote를 별도로 보내는 이유는 이함수가 리턴되야 session의 remote가 갱신되므로.. return(remote); }