private void InitMain() { Controls.Clear(); ClientSize = new Size(400, 200); Text = "Dice Game. Main"; Button StartClient = new Button() { Parent = this, Location = new Point((ClientRectangle.Width / 2) - 150, (ClientRectangle.Height / 2) - 50), Size = new Size(300, 40), Text = "Запустить клиент" }; Button StartServer = new Button() { Parent = this, Location = new Point((ClientRectangle.Width / 2) - 150, (ClientRectangle.Height / 2) + 10), Size = new Size(300, 40), Text = "Запустить сервер" }; StartClient.Click += (object sender, EventArgs e) => { if (!(Client is null)) { Client.Close(); } Client = new ClientForm(GroupAdress, ClientReceive, ServerReceive) { Size = new Size(800, 600), Text = "Client" }; Client.Show(); Client.FormClosing += (object esender, FormClosingEventArgs ee) => { StartClient.Enabled = true; }; StartClient.Enabled = false; }; StartServer.Click += (object sender, EventArgs e) => { if (!(Server is null)) { Server.Close(); } Server = new ServerForm(GroupAdress, ServerReceive, ClientReceive) { Size = new Size(400, 600), Text = "Sever" }; Server.SetConsole(); Server.FormClosing += (object esender, FormClosingEventArgs ee) => { StartServer.Enabled = true; }; StartServer.Enabled = false; }; }
public Client(ClientForm form1, int port) { Alive = true; localPort = port; thisPlayer.Name = form1.playerName; thisPlayer.location = Location.bottom; players.Add(thisPlayer); form = form1; EndPoint localPoint = new IPEndPoint(IPAddress.Parse(localAddress), localPort); socket.Bind(localPoint); serverEndPoint = new IPEndPoint(IPAddress.Parse(remoteAddress), remotePort); Thread receiveThread = new Thread(new ThreadStart(ReceiveMessage)); receiveThread.Start(); SendMessage($"подключился {form.playerName}"); }