Пример #1
0
        private void btncnt_Clicked(object sender, EventArgs e)
        {
            t?.Abort();
            switch (btncnt.Text)
            {
            case "Start server":
                if (server != null)
                {
                    server.ClientConnected    -= Server_ClientConnected;
                    server.ClientDisconnected -= Server_ClientDisconnected;
                }
                server = new TCPServer(ip.Text, ushort.Parse(port.Text));
                //server.AutoRelistenForMessages = false;
                //server.BeginReceiveOnConnection = false;
                server.ClientConnected    += Server_ClientConnected;
                server.ClientDisconnected += Server_ClientDisconnected;
                server.ClientDataReceived += Server_ClientDataReceived;
                btncnt.Text = "Stop server";
                server.StartListening();
                break;

            case "Stop server":
                btncnt.Text = "Start server";
                server.BroadcastString("Server shutdown");
                try { server.Shutdown(); ClientDisplayers.Clear(); clientLister.ItemsSource = null; clientLister.ItemsSource = ClientDisplayers; } catch { }
                break;
            }
        }
Пример #2
0
 private void broadcastBtn_Clicked(object sender, EventArgs e)
 {
     server.BroadcastString(smsg.Text);
 }