コード例 #1
0
ファイル: TcpConsole.cs プロジェクト: SoupPenguin/soupmix
		public void NewClient (IAsyncResult e)
		{
			TcpClient c = listener.EndAcceptTcpClient (e);
			NetworkStream s = c.GetStream ();
			int ecode = 0;

			byte[] msg = BuildPacket (new { errorCode = ecode });
			if (s.CanWrite) {
				s.Write (msg, 0, msg.Length);
				s.Flush ();
			} else {// Well this sucks
				s.Close();
				return;
			}
			if (ecode == 0) {
				lastLogin = DateTime.Now;
				lastIP = ((IPEndPoint)c.Client.RemoteEndPoint).Address.ToString();
				TcpState state = new TcpState();
				state.stream = s;
				state.buffer = new byte[BUFFERSIZE];
				s.BeginRead(state.buffer,0,BUFFERSIZE,ClientMessage,state);
			} else {
				s.Close();
			}
			


			listener.BeginAcceptTcpClient(NewClient,null);
		}