0

Okay, so I've been trying to create a UDP Server (I've got the TCP one done but I need both for my project). However, whenever using the following code:

UdpClient whatever = new UdpClient(11000);

I always get a SocketException with any port number (not just 11000), unless I don't specify a port at all. This won't work for me because I need to have it specifically on one port only.

I've even copied/pasted the Microsoft example (http://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient.aspx) into a new project and tried it, and it compiles fine but I still get a socketexception with no explanation when initialising the UdpClient with a port.

Any ideas? This is doing my head in...

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by Anon17
0

From the same site you linked:

If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code. Once you have obtained this code, you can refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error.

0

It provides error 10022, which is a invalid argument applied - However, I fail to see how providing a port is an invalid argument.

I've even tried copying and pasting UDP server examples into new C# projects (to check if it's anything in my project at all), but I still get that exception/error on the UdpClient initialisation...

0

I don't think it could be that - A Java server that I did a while back works (UDP on any of the ports I try), and disabling the firewall/antivirus didn't affect the C# server at all.

The problem persists for ANY port except 0, although it seems to work if I add an IP before the port in new UdpClient - However would adding an IP address restrict the ability to receive data from all clients connecting to that port (in my case, 11010)?

0

Okay, so I've upgraded to SP3 (Windows XP, was SP2 before), NET framework 4 (from 3.5) and Visual C# 2010 Express (was Visual C# 2008 Express).

Still no change, Error Code 10022. I've been searching online for hours and I've still found no solution - Every UDP server example gives me that error as does my own server.

0

EDIT - Ignore this, Connect is only for clients... Binding still doesn't work...

Edited by Anon17: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.