private void ReceivingOperation() { IdSync(); string recStr; try{ while (isConnected) { recStr = streamReader.ReadLine(); if (recStr != null) { ConsoleMsgQueue.EnqueMsg(clientId + ": Received: " + recStr, 0); ReceiveQueue.EnqueMsg(new NetworkMessage(recStr)); } else { isConnected = false; } } }catch (Exception e) { ConsoleMsgQueue.EnqueMsg(clientId + ": ReceiveOperation: " + e.Message); } ConsoleMsgQueue.EnqueMsg(clientId + ": Disconnected."); isConnected = false; ClientManager.CloseClient(clientId); streamReader.Close(); }
/* * private void IdSync(){//client에게 네트워크에서의 id를 가르쳐주는 과정 * string recStr; * * try{ * while(isConnected){ * recStr = streamReader.ReadLine(); * * if(recStr != null){ * ConsoleMsgQueue.EnqueMsg(clientId + ": Received: " + recStr, 0); * NetworkMessage nm = new NetworkMessage(recStr); * if(nm.Adress.Attribute.Equals("-1")){//발신자 id가 -1이면 클라이언트에게 네트워크 id 전송해줌 * MsgSegment h = new MsgSegment(MsgAttr.setup); * MsgSegment b = new MsgSegment(MsgAttr.Setup.reqId, clientId.ToString()); * NetworkMessage idInfo = new NetworkMessage(h, b); * Send(idInfo.ToString()); * }else{ * break; * } * }else{ * isConnected = false; * } * } * }catch(Exception e){ * ConsoleMsgQueue.EnqueMsg(clientId + ": IdSync: " + e.Message); * } * * ConsoleMsgQueue.EnqueMsg(clientId + ": IdSync Done."); * }*/ public void ShutDown() { streamWriter.Close(); streamReader.Close(); socket.Shutdown(SocketShutdown.Both); ClientManager.CloseClient(clientId); }
private void ReceivingOperation() { //IdSync(); /* * MsgSegment h = new MsgSegment(MsgAttr.local, ""); * MsgSegment b = new MsgSegment(MsgAttr.Local.disconnect, clientId.ToString()); * NetworkMessage dyingMsg = new NetworkMessage(h, b); */ string recStr; try{ while (isConnected) { recStr = streamReader.ReadLine(); if (recStr != null) { Debug.Log(clientId + ": Received: " + recStr); ReceiveQueue.SyncEnqueMsg(recStr); } else { isConnected = false; } } }catch (Exception e) { Debug.Log(clientId + ": ReceiveOperation: " + e.Message); //ReceiveQueue.SyncEnqueMsg(dyingMsg); } //ConsoleMsgQueue.EnqueMsg(clientId + ": Disconnected."); isConnected = false; ClientManager.CloseClient(clientId); streamReader.Close(); }