コード例 #1
0
 private void server_data_arrival(easy_socket.udp.Socket_Server s, easy_socket.udp.EventArgs_ReceiveDataSocketUDP e)
 {
     System.Net.IPEndPoint ipep = (System.Net.IPEndPoint)e.remote_host_EndPoint;
     if (!this.textBox_telnet.Text.EndsWith("\r\n"))
     {
         this.textBox_telnet_add("\r\n");
     }
     this.textBox_telnet_add("Data from " + ipep.Address + " port " + ipep.Port.ToString() + " :\r\n");
     if (this.checkBox_rcv_hexa_data.Checked)
     {
         this.textBox_telnet_add(easy_socket.hexa_convert.byte_to_hexa(e.buffer, " ") + " ");
     }
     else
     {
         string strdata = System.Text.Encoding.Default.GetString(e.buffer, 0, e.buffer_size);
         this.textBox_telnet_add(strdata);
     }
     if (this.b_server_only)
     {
         //update remote host
         this.myremoteip   = ((System.Net.IPEndPoint)e.remote_host_EndPoint).Address.ToString();
         this.myremoteport = ((System.Net.IPEndPoint)e.remote_host_EndPoint).Port;
     }
     if (echo_server)
     {
         srv.send(e.buffer, e.remote_host_EndPoint);
     }
 }
コード例 #2
0
        private void socket_event_Socket_Server_Data_Arrival(easy_socket.udp.Socket_Server sender, easy_socket.udp.EventArgs_ReceiveDataSocketUDP e)
        {
            int res = System.Threading.WaitHandle.WaitAny(this.HexaViewWaitHandles);

            if (res == 0) // close event
            {
                return;
            }

            System.Drawing.Color color = System.Drawing.Color.Black;
            bool b_transmit            = false;

            System.Net.IPEndPoint ipep = (System.Net.IPEndPoint)e.remote_host_EndPoint;
            // if data comes from remote server, transfer data to last client
            if ((ipep.Address.ToString() == this.remote_server_ip) && (ipep.Port == this.remote_server_port))
            {
                if (b_last_client)
                {
                    // transfer data if required
                    if (this.radioButton_srv_to_clt_allow.Checked)
                    {
                        b_transmit = true;
                    }
                    else if (this.radioButton_srv_to_clt_block.Checked)
                    {
                        b_transmit = false;
                    }
                    else// query
                    {
                        string msg = "Do you want to allow the transfer of following data from " + ipep.Address + ":" + ipep.Port.ToString() + "?\r\n"
                                     + "Hexa Data:\r\n"
                                     + this.split_in_multiple_lines(easy_socket.hexa_convert.byte_to_hexa(e.buffer), 50)
                                     + "Text Data:\r\n"
                                     + this.split_in_multiple_lines(System.Text.Encoding.Default.GetString(e.buffer), 50);

                        b_transmit = (MessageBox.Show(this, msg, "Tcp Interactive", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes);
                    }
                    if (b_transmit)
                    {
                        this.socket.send(e.buffer, this.last_client_ip, this.last_client_port);
                        color = System.Drawing.Color.Black;
                    }
                    else
                    {
                        color = System.Drawing.Color.Red;
                    }
                }
                else
                {
                    color      = System.Drawing.Color.Red;
                    b_transmit = false;
                }
            }
            else// data is from a client, transfer it to remote server
            {
                // update info about last clt
                this.last_client_ip   = ipep.Address.ToString();
                this.last_client_port = ipep.Port;
                if (!this.b_last_client)
                {
                    this.b_last_client = true;
                }

                // transfer data if required
                if (this.radioButton_clt_to_srv_allow.Checked)
                {
                    b_transmit = true;
                }
                else if (this.radioButton_clt_to_srv_block.Checked)
                {
                    b_transmit = false;
                }
                else// query
                {
                    string msg = "Do you want to allow the transfer of following data from " + ipep.Address + ":" + ipep.Port.ToString() + "?\r\n"
                                 + "Hexa Data:\r\n"
                                 + this.split_in_multiple_lines(easy_socket.hexa_convert.byte_to_hexa(e.buffer), 50)
                                 + "Text Data:\r\n"
                                 + this.split_in_multiple_lines(System.Text.Encoding.Default.GetString(e.buffer), 50);
                    b_transmit = (MessageBox.Show(this, msg, "Tcp Interactive", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes);
                }
                if (b_transmit)
                {
                    this.socket.send(e.buffer, this.remote_server_ip, this.remote_server_port);
                    color = System.Drawing.Color.Blue;
                }
                else
                {
                    color = System.Drawing.Color.Violet;
                }
            }
            if (b_transmit)
            {
                this.add_info("Data from " + ipep.Address + ":" + ipep.Port.ToString().ToString());
            }
            else
            {
                this.add_info("Data from " + ipep.Address + ":" + ipep.Port.ToString() + "(Blocked)");
            }
            // color depends of sender && user action
            this.add_data(e.buffer, color);
            this.refresh_data();
            this.evtNotWrittingData.Set();
        }