コード例 #1
0
ファイル: form_main.cs プロジェクト: EdgeKiller/eNetwork2
        private void Client_OnDataReceived(byte[] buffer)
        {
            PacketReader pr = new PacketReader(buffer);
            Byte ID = pr.ReadByte();

            if(ID == 1)
            {
                int id = pr.ReadInt32();
                string message = pr.ReadString();
                string msg = id + " : " + message;
                listBox_messages.Items.Add(msg);
            }
        }
コード例 #2
0
ファイル: eClient.cs プロジェクト: EdgeKiller/eNetwork2
        /// <summary>
        /// Connect the client
        /// </summary>
        /// <returns>Success</returns>
        public bool Connect()
        {
            try
            {
                Client.Connect(Hostname, Port);

                if (ClientRequest != null)
                    ClientRequest.Connect(Hostname, PortRequest);

                byte[] idBuffer = new byte[4];
                Client.GetStream().Read(idBuffer, 0, idBuffer.Length);

                using (PacketReader pr = new PacketReader(idBuffer))
                {
                    ID = pr.ReadInt32();
                }

                if (OnConnected != null)
                    OnConnected();
                StartHandle();

                DebugMessage("Connected successfully");

                Connected = true;

                return true;
            }
            catch (Exception ex)
            {
                DebugMessage("Failed to connect : " + ex.Message);
                Disconnect();
                return false;
            }
        }