Socket Exception

S

Steve Walton

We have a little server application that sends data down to a client application via a TCP/IP socket over port 30006. These
applications are both written in C#. They have been working on our site for a couple of years. Now, we are trying to use these
applications at another site and we get an exception on the following line:-

Socket oRequest = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);

The exception identifies itself as 10022 which is described as invalid argument.

My questions are

1) Is the Socket creation line an example of bad programming and we have been lucky to get away with it for 2 years?

1a) What is a better command to create a new Socket object to use over TCP/IP?

2) What are the circumstances in which the above line would fail? As far as we can see, the PCs have TCP/IP installed on them.
Internet explorer works for example.

Thanks for any help given.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Steve Walton said:
We have a little server application that sends data down to a client
application via a TCP/IP socket over port 30006. These
applications are both written in C#. They have been working on our site
for a couple of years. Now, we are trying to use these
applications at another site and we get an exception on the following
line:-

Socket oRequest = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);

The exception identifies itself as 10022 which is described as invalid
argument.

My questions are

1) Is the Socket creation line an example of bad programming and we have
been lucky to get away with it for 2 years?

If that constructor exist, then you could use it. personally I see nothing
wrong with it.
1a) What is a better command to create a new Socket object to use over
TCP/IP?

Personally I always tend to use TcpClient over socket. Regarding how to
create your code seems ok
2) What are the circumstances in which the above line would fail? As far
as we can see, the PCs have TCP/IP installed on them.
Internet explorer works for example.

Did you see if there were an InternalException ?
 
C

Chris Mullins [MVP]

Steve Walton said:
[...]
Now, we are trying to use these
applications at another site and we get an exception on the following
line:-

Socket oRequest = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);

The exception identifies itself as 10022 which is described as invalid
argument.

I don't know what that error really means there. It's.... strange. Do you
have a full stack trace on the exception you can share?
My questions are

1) Is the Socket creation line an example of bad programming and
we have been lucky to get away with it for 2 years?

This is completly legit. We do it all over the place, on tens of thousands
of computers. No trouble.
1a) What is a better command to create a new
Socket object to use over TCP/IP?

It dependson your use case. I use the command you described above. There's
also TCPClient and Network stream.
2) What are the circumstances in which the above line would
fail? As far as we can see, the PCs have TCP/IP installed on them.

I'm not sure. Got a full exception you can provide?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top