public void checker() { if (result.Length > 100) { string[] parray = SplitInParts(result, 100).ToArray(); foreach (string s in parray) { result = s; ResultSend(); } result = ""; return; } ResultSend(); }
public void ResultSend() { try { sendresult = result; string TextBoxer = sendresult; //TEXT string IPBoxer = opip; //EMPFÄNGER byte[] myWriteBuffer = Encoding.ASCII.GetBytes(TextBoxer); //Socket definieren Socket bcSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //EndPoint definieren bzw. Ziel des Broadcastes IPEndPoint iep1 = new IPEndPoint(IPAddress.Parse(IPBoxer), 24711); //Optionen auf den Socket binden bcSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1); //Broadcast senden bcSocket.SendTo(myWriteBuffer, iep1); //Socket schliessen, nach erfolgreichem Senden des Broadcastes bcSocket.Close(); } catch (Exception ex) { Dispatcher.Invoke(new Action(() => this.listBox1.Items.Add("Error sending answer, i guess the IP is invalid"))); return; } }(CLIENT) public void Receive() { try { Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint iep = new IPEndPoint(IPAddress.Any, 24711); sock.Bind(iep); EndPoint ep = (EndPoint)iep; byte[] data = new byte[1024]; int recv = sock.ReceiveFrom(data, ref ep); string stringData = Encoding.ASCII.GetString(data, 0, recv); data = new byte[1024]; recv = sock.ReceiveFrom(data, ref ep); stringData = Encoding.ASCII.GetString(data, 0, recv); Dispatcher.Invoke(new Action(() => this.listBox1.Items.Add(stringData))); sock.Close(); sock.Dispose(); Receive(); // return; } catch (Exception ex) { MessageBox.Show("Fehler in Methode" + Environment.NewLine + Environment.NewLine + ex + Environment.NewLine + Environment.NewLine + "Möglicherweise ist ein Port blockiert.", "Ausführungsfehler!"); } }I was hoping someone can help me with this, i'm trying to solve this problem for a week and really tried my best.Thank you !!