Answer the question
In order to leave comments, you need to log in
How to send a packet to a specific ip, tcp client client BeginSendTo?
Good day to all, I need to send a message from the client to the client (there is a server between them, but I think it will not be needed).
The code of the button on the form for sending the byte[] array, ip is taken from the listbox.
string[] s = listStation.SelectedItem.ToString().Split(':');
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(s[0]), Convert.ToInt32(s[1]));
Socket ss = new Socket(ipep.Address.AddressFamily,
SocketType.Stream,
ProtocolType.Tcp);
client.Client.BeginSendTo(msg, 0, msg.Length, 0, ipep, new AsyncCallback(DoAcceptTcpClientCallback), ss);
public static ManualResetEvent allDone = new ManualResetEvent(false);
public static void DoAcceptTcpClientCallback(IAsyncResult ar)
{
// Get the listener that handles the client request.
TcpListener listener = (TcpListener)ar.AsyncState;
// End the operation and display the received data on
// the console.
TcpClient client = listener.EndAcceptTcpClient(ar);
// Process the connection here. (Add the client to a
// server table, read data, etc.)
//Console.WriteLine("Client connected completed");
// Signal the calling thread to continue.
allDone.Set();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question