コード例 #1
0
ファイル: MainForm.cs プロジェクト: gaonsoflt/isps
        void client_DataReceived(Client sender, ReceiveBuffer e)
        {
            try
            {
                Packet  pkt    = DataPacket.DataParser(e.BufStream, e.pkt);
                PktType header = pkt.type;
                UpdateCompLogMsg(sender.name + " - Received data: " + pkt.ToString());
                switch (header)
                {
                case PktType.AUTH:
                    UpdateCompImage(pkt.fingerPrint);
                    UpdateCompMatchedUser(sender.RunAuth(pkt));
                    //sender.RunAuth(pkt);
                    break;

                case PktType.PASSENGER:
                    sender.RunPassenger(pkt);
                    break;

                case PktType.ORDER:
                    sender.RunOrder(pkt);
                    break;
                }
            }
            catch (Exception ee)
            {
                UpdateCompLogMsg(ee.Message);
            }
        }
コード例 #2
0
        public void receiveCallBack(IAsyncResult ar)
        {
            try
            {
                int rec = socket.EndReceive(ar);

                if (rec == 0)
                {
                    if (Disconnected != null)
                    {
                        Disconnected(this);
                        return;
                    }
                }

                if (rec != headBuf.Length)
                {
                    throw new Exception();
                }
            }
            catch (SocketException se)
            {
                switch (se.SocketErrorCode)
                {
                case SocketError.ConnectionAborted:
                case SocketError.ConnectionReset:
                    if (Disconnected != null)
                    {
                        Disconnected(this);
                        return;
                    }
                    break;
                }
            }
            catch (ObjectDisposedException)
            {
                return;
            }
            catch (NullReferenceException)
            {
                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            buffer = new ReceiveBuffer(headBuf);
            socket.BeginReceive(buffer.Buffer, 0, buffer.Buffer.Length, SocketFlags.None, receivePacketCallBack, null);
        }