Answer the question
In order to leave comments, you need to log in
How to create a function with parameters in a stream?
I looked all over the Internet, I could not find a normal answer on how to create a new thread with a function with parameters in it.
Here is my code:
<br>
static void Main(string[] args)<br>
{<br>
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);<br>
socket.Bind(new IPEndPoint(IPAddress.Any, 25444));<br>
socket.Listen(32);<br>
while (true)<br>
{<br>
var clientSocket = socket.Accept();<br>
var endpoint = new IPEndPoint("127.0.0.1", 25443);<br>
var thread = new Thread(ParameterizedThreadStart(UdpClientReceive(clientSocket, endpoint)));<br>
thread.Start();<br>
}<br>
}<br>
<br>
private static void UdpClientReceive(Socket socket, IPEndPoint endpoint)<br>
{<br>
var udpClient = new UdpClient();<br>
udpClient.Connect(endpoint);<br>
var clientBuffer = new byte[4096];<br>
while (true)<br>
{<br>
socket.Receive(clientBuffer);<br>
udpClient.Send(clientBuffer, clientBuffer.Length);<br>
}<br>
}<br>
Answer the question
In order to leave comments, you need to log in
Is it possible to call it through another function?
like this
Thread thread = new Thread(() => {
unt_client_recv(client, "127.0.0.1", 25443);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question