public static void StartClient(string M, LogicObjects.IPDATA ip) { try { //IPEndPoint ipEndPoint = new IPEndPoint(ip, 8000); IPEndPoint ipEndPoint = new IPEndPoint(ip.IP, ip.PORT); //Debugging.Log("Starting: Creating Socket object"); Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sender.Connect(ipEndPoint); Debugging.Log($"Successfully connected to {sender.RemoteEndPoint}"); string sendingMessage = M; //string sendingMessage = "Hello World Socket Test"; //Debugging.Log("Creating message:{0}", sendingMessage); byte[] forwardMessage = Encoding.Default.GetBytes(sendingMessage); sender.Send(forwardMessage); //int totalBytesReceived = sender.Receive(receivedBytes); //Debugging.Log("Message provided from server: {0}", Encoding.ASCII.GetString(receivedBytes, 0, totalBytesReceived)); sender.Shutdown(SocketShutdown.Both); sender.Close(); } catch (ArgumentNullException ane) { Debugging.Log($"ArgumentNullException : {ane}"); } catch (SocketException se) { Debugging.Log($"SocketException : {se}"); } catch (Exception e) { Debugging.Log($"Unexpected exception : {e}"); } }
//Controls private void BtnAddIP_Click_1(object sender, EventArgs e) { LogicObjects.IPDATA NewIP = new LogicObjects.IPDATA(); string IPText = txtIP.Text; IPAddress IP; try { IP = IPAddress.Parse(IPText); } catch { IP = null; } if (IP == null) { try { IP = Dns.GetHostEntry(IPText).AddressList[0]; } catch { IP = null; } } if (IP == null) { MessageBox.Show("IP Address not valid"); txtIP.Focus(); txtIP.SelectAll(); return; } NewIP.IP = IP; Debugging.Log(IP.ToString()); NewIP.PORT = (int)NudPort.Value; NewIP.DisplayName = $"{IPText}:{NewIP.PORT}"; IPS.Add(NewIP); UpdateFormItems(); txtIP.Focus(); txtIP.SelectAll(); }
public static void OnlinePlay_TriggerAddRemoteToIPList(LogicObjects.MMRTpacket Data) { LogicObjects.IPDATA NewIP = new LogicObjects.IPDATA(); try { NewIP.IP = IPAddress.Parse(Data.IPData.IP); } catch { return; } NewIP.PORT = Data.IPData.PORT; NewIP.DisplayName = $"{NewIP.IP}:{NewIP.PORT}"; IPS.Add(NewIP); if (CurrentOpenForm != null) { CurrentOpenForm.UpdateFormItems(); } }