Exemplo n.º 1
0
        private void handleTCPData(MySocket mySocket, byte[] data)
        {
            byte[] CRPData = BytesUtil.subBytes(data, CRPHead.length);
            byte[] head    = BytesUtil.subBytes(data, 0, CRPHead.length);
            switch (checkDataType(head))
            {
            case CRPHead.REQUEST_LOGIN:
                handleLogin(mySocket, CRPData);
                break;

            case CRPHead.REQUEST_LOGOUT:
                handleLogout(mySocket, CRPData);
                break;

            case CRPHead.SEND_MESSAGE:
                handleMessage(mySocket, CRPData);
                break;

            case CRPHead.SEND_PICTURE:
                handlePicture(mySocket, CRPData);
                break;

            case CRPHead.REQUEST_VIDEO_START:
                handleVideoStart(mySocket, CRPData);
                break;

            case CRPHead.REQUEST_VIDEO_STOP:
                handleVideoStop(mySocket, CRPData);
                break;
            }
        }
Exemplo n.º 2
0
 private void removeUser(MySocket mySocket)
 {
     tcpSockets.Remove(mySocket);
     mySocket.disConnect();
     removeUserHandler.Invoke(mySocket);
     mySocket = null;
 }
Exemplo n.º 3
0
 private void sendCRPPacket(MySocket tcpSocket, int headType, CRPBody body)
 {
     byte[] bodyBytes = body.getBytes();
     byte[] packet    = new byte[CRPHead.length + bodyBytes.Length];
     BytesUtil.Append(packet, CRPHead.getHeadBytes(headType));
     BytesUtil.Append(packet, bodyBytes, CRPHead.length);
     tcpSocket.send(packet);
 }
Exemplo n.º 4
0
        private void handleMessage(MySocket mySocket, byte[] cRPData)
        {
            Body4SendMessage messageBody = Body4SendMessage.nullBody;

            messageBody.readBytes(cRPData);
            messageHandler.Invoke(messageBody.Message);
            forwardMessage(messageBody.Message);
        }
Exemplo n.º 5
0
 private void dataGridViewDeleteUser(MySocket socket)
 {
     for (int i = 0; i < dataGridView1.Rows.Count; i++)
     {
         if (dataGridView1.Rows[i].Tag.ToString() == socket.Name)
         {
             dataGridView1.Rows.RemoveAt(i);
         }
     }
     ;
 }
Exemplo n.º 6
0
 public void startListening(int TCPPort)
 {
     tcpSocketListener.Bind(new IPEndPoint(IPAddress.Any, TCPPort));
     tcpSocketListener.Listen(10);
     while (true)
     {
         Socket   socket   = tcpSocketListener.Accept();
         MySocket mySocket = new MySocket(socket);
         new Thread(new ParameterizedThreadStart(startSocketListening)).Start(mySocket);
     }
 }
Exemplo n.º 7
0
 private void handleVideoStart(MySocket mySocket, byte[] cRPData)
 {
     if (livingName != "")
     {
         sendCRPPacket(mySocket, CRPHead.RESPONSE_VIDEO_START, new Body4ResponseVideoStart(false, "直播功能被" + livingName + "占用"));
         return;
     }
     initVideo();
     livingName = mySocket.Name;
     videoStartHandler.Invoke(mySocket);
     sendCRPPacket(mySocket, CRPHead.RESPONSE_VIDEO_START, new Body4ResponseVideoStart(true));
 }
Exemplo n.º 8
0
 private void deleteUser(MySocket socket)
 {
     if (dataGridView1.InvokeRequired)
     {
         Action <MySocket> action = (x) =>
         {
             dataGridViewDeleteUser(x);
         };
         dataGridView1.Invoke(action, socket);
     }
     else
     {
         dataGridViewDeleteUser(socket);
     }
 }
Exemplo n.º 9
0
        private void dataGridViewAddUser(MySocket socket)
        {
            DataGridViewRow row   = new DataGridViewRow();
            var             data1 = new DataGridViewTextBoxCell();

            data1.Value = socket.Name;
            row.Cells.Add(data1);
            var data2 = new DataGridViewTextBoxCell();

            data2.Value = socket.getSocketIP().ToString();
            row.Cells.Add(data2);
            var data3 = new DataGridViewTextBoxCell();

            data3.Value = socket.getTCPPort().ToString();
            row.Cells.Add(data3);
            var data4 = new DataGridViewTextBoxCell();

            data4.Value = socket.getUDPPort().ToString();
            row.Cells.Add(data4);
            row.Tag = socket.Name;
            dataGridView1.Rows.Add(row);
        }
Exemplo n.º 10
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (begin_flag == 0)
            {
                SA = new MySocket(IPTextBox.Text, int.Parse(PortTextBox.Text));
                if (SA.Listener() == 1)
                {
                    thread = new Thread(new ThreadStart(SA.Receive));
                    thread.Start();
                    begin_flag       = 1;
                    BeginButton.Text = "停止";
                }
            }

            else
            {
                SA.Stop();
                thread.DisableComObjectEagerCleanup();

                begin_flag       = 0;
                BeginButton.Text = "开始";
            }
        }
Exemplo n.º 11
0
        private void handleLogin(MySocket mySocket, byte[] cRPData)
        {
            Body4RequestLogin body = Body4RequestLogin.nullBody;

            body.readBytes(cRPData);
            string name = body.Name;

            foreach (MySocket sock1 in tcpSockets)
            {
                if (sock1.Name == name)
                {
                    responseLogin(mySocket, false, "名字已被使用");
                    return;
                }
            }
            mySocket.Name      = name;
            mySocket.UdpAdress = new IPEndPoint(mySocket.getSocketIP(), body.Port);
            tcpSockets.Add(mySocket);
            addUserHandler.Invoke(mySocket);
            responseLogin(mySocket, true);
            string message = name + "进入聊天室";

            forwardMessage(message);
        }
Exemplo n.º 12
0
 public Object4Send(byte[] b, MySocket m)
 {
     bytes  = b;
     socket = m;
 }
Exemplo n.º 13
0
 private void handleLogout(MySocket mySocket, byte[] cRPData)
 {
     removeUser(mySocket);
 }
Exemplo n.º 14
0
 private void handlePicture(MySocket mySocket, byte[] cRPData)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
 private void handleVideoStop(MySocket mySocket, byte[] cRPData)
 {
     livingName = "";
     videoStopHandler.Invoke();
 }
Exemplo n.º 16
0
 private void responseLogin(MySocket socket, bool isSuccess, string failInfo = "")
 {
     sendCRPPacket(socket, CRPHead.RESPONSE_LOGIN, new Body4ResponseLogin(isSuccess, failInfo));
 }