Esempio n. 1
0
        public void ClientAdded(object sender, EventArgs e)
        {
            TcpClient tcpClient  = ((MyEventArgs)e).clientSock;
            String    remoteIP   = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString();
            String    remotePort = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Port.ToString();

            UpdateClientList(remoteIP + " : " + remotePort + " : " + Myserver.Resolve(remoteIP, false), "Add");
        }
        public static void SendMessage(object msg, string key)
        {
            int       seek  = 0;
            const int count = 102400;
            // byte[] buffer;
            Socket handler = getClient(key);

            try
            {
                //   byte[] o = ObjectToByteArray(msg);

                ByteArrayBuilder b = new ByteArrayBuilder();
                b.Append(ObjectToByteArray(msg));

                byte[] ol = BitConverter.GetBytes(b.Length);

                handler.BeginSend(ol, 0, ol.Length, 0, new AsyncCallback(SendCallBack), handler);

                //count = b.Length;
                int length = b.Length;

                while (length > count)
                {
                    handler.BeginSend(b.ToArray(seek, count), 0, count, 0, new AsyncCallback(SendCallBack), handler);
                    //handler.BeginSend(buffer, 0, count, 0, new AsyncCallback(SendCallBack), handler);
                    seek  += count;
                    length = length - count;
                }

                handler.BeginSend(b.ToArray(seek, length), 0, length, 0, new AsyncCallback(SendCallBack), handler);
            }
            catch (SocketException socketException)
            {
                //WSAECONNRESET, the other side closed impolitely
                if (socketException.ErrorCode == 10054 ||
                    ((socketException.ErrorCode != 10004) && (socketException.ErrorCode != 10053)))
                {
                    // Complete the disconnect request.
                    String remoteIP   = ((IPEndPoint)handler.RemoteEndPoint).Address.ToString();
                    String remotePort = ((IPEndPoint)handler.RemoteEndPoint).Port.ToString();
                    Myserver.DisconnectClient(remoteIP, remotePort);

                    handler.Close();
                    handler = null;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message, "Information");
            }
        }
Esempio n. 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!server)
            {
                server = true;
                Myserver.Start(8080);
                button1.Text = "Stop Server";
            }
            else
            {
                server = false;

                Myserver.Stop();
                tvClientList.Nodes[0].Nodes.Clear();

                button1.Text = "Start Server";
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Event Called when Main Form is closed. It stops the server and Disposes all Resources
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
 {
     Myserver.Stop();
 }
Esempio n. 5
0
        private void tvClientList_DoubleClick(object sender, System.EventArgs e)
        {
            int index = tvClientList.SelectedNode.Index;

            Myserver.Show(index);
        }