コード例 #1
0
ファイル: TrackConnection.cs プロジェクト: slotcar-ai/player
        public void ReceiveTrackUpdates(Socket socket)
        {
            try
            {
                RecieveStateObject state = new RecieveStateObject();
                state.workSocket = socket;

                socket.BeginReceive(state.buffer, 0, RecieveStateObject.BufferSize, 0,
                                    new AsyncCallback(ReceiveTrackUpdate), state);
            }
            catch (Exception e)
            {
                CloseSocket(socket);
                Console.WriteLine(e.ToString());
            }
        }
コード例 #2
0
ファイル: TrackConnection.cs プロジェクト: slotcar-ai/player
        private void ReceiveTrackUpdate(IAsyncResult ar)
        {
            try
            {
                RecieveStateObject state  = (RecieveStateObject)ar.AsyncState;
                Socket             client = state.workSocket;

                int bytesRead = client.EndReceive(ar);

                if (bytesRead > 0)
                {
                    string value = Encoding.ASCII.GetString(state.buffer, 0, bytesRead);
                    state.sb.Append(value);
                    Console.WriteLine(value);
                }
                client.BeginReceive(state.buffer, 0, RecieveStateObject.BufferSize, 0,
                                    new AsyncCallback(ReceiveTrackUpdate), state);
            }
            catch (Exception e)
            {
                CloseSocket((Socket)ar.AsyncState);
                Console.WriteLine(e.ToString());
            }
        }