Write a TcpClient and MulticastClient forms based of this codes: Tcp:"{ TopClient…
- User
Write a TcpClient and MulticastClient forms based of this codes: Tcp:"{ TopClient client; public Form1() { InitializeComponent(); } }
private void button1_Click(object sender, EventArgs e) { try { IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse(textBox1.Text), Convert.ToInt32(textBox2.Text)); client = new TopClient(); client.Connect(endPoint); NetworkStream netream = client.GetStream(); byte[] barrey = Encoding.Unicode.GetBytes(textBox3.Text); netream.Write(barrey, 0, barrey.Length); client.Close(); } catch (SocketException sockEx) { MessageBox.Show("Исключение сокета: " + sockEx.Message); } catch (Exception Ex) { MessageBox.Show("Исключение: " + Ex.Message); } }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { if (client != null) client.Close(); }" Multicast: "namespace MulticastClient { public partial class Forml : Form { delegate void AppendText(string text); void Listner() { while (true) { Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IFEndPoint ipep = new IFEndPoint(IPAddress.Any, 8801); sod.Bind(ipep); IPAddress ip = IPAddress.Parse("224.5.5.5"); soc.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, IPAddress.Any)); byte[] buff = new byte[4096]; soc.Recolve(buff); this.Invoke(new AppendText(AppendTextProc), Encoding.Unicode.GetString(buff)); soc.Close(); } }
codeThread listen; public Forml() { InitializeComponent(); listen = new Thread(new ThreadStart(Listner)); listen.IsBackground = true; listen.Start(); } void AppendTextProc(string text) { dataOutput.Text = text; } }}" so they would work with this server: "using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; using System.Net; using System.Net.Sockets; using System.Diagnostics.Eventing.Reader;
namespace TCPMulticastServer { class TcpMulticastServer { private const int TcpPort = 8800; private const int UdpPort = 8801; private const string MulticastIp = "224.5.5.5"; private readonly List _clients = new List(); public string clIP = null; public string message = null; public Dictionary<string, string> users = new Dictionary<string, string>();
code - Assistant