Hi there,
In C# i would like to listen to the following socket:
Local Address: 0.0.0.0
Local Port: 1498
Remote Adress: 127.0.0.1
Remote Port: 40001
Protocol: UDP
I tried with the following code:
I cant recieve anything, although Socket Spy Packet Sniffer does show packet data is being send. Any suggestions on how to achieve this :s.
Thx in advance!
In C# i would like to listen to the following socket:
Local Address: 0.0.0.0
Local Port: 1498
Remote Adress: 127.0.0.1
Remote Port: 40001
Protocol: UDP
I tried with the following code:
Code:
try
{
Socket soUdp = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
soUdp.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
string RemoteIP = "127.0.0.1";
IPAddress remoteadres = IPAddress.Parse(RemoteIP);
IPEndPoint LocalIpEndPoint = new IPEndPoint(remoteadres, 40001);
//soUdp.Bind(LocalIpEndPoint);
soUdp.Connect(LocalIpEndPoint);
while (true)
{
Byte[] recieved = new Byte[1500];
IPEndPoint tmpIpEndPoint = new IPEndPoint(remoteadres, 40001);
EndPoint remoteEP = (tmpIpEndPoint);
int BytesRecevied = soUdp.ReceiveFrom(recieved, ref remoteEP);
string dataRecieved = System.Text.ASCIIEncoding.ASCII.GetString(recieved);
Console.WriteLine(dataRecieved.ToString());
}
}
catch(Exception exc)
{
Console.WriteLine("Socket Exception:\n" + exc.ToString());
}
Console.WriteLine("Press enter to close window");
Console.ReadLine();
Thx in advance!
Comment