473,624 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket Exception

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(AddressF amily.InterNetw ork,SocketType. Stream,Protocol Type.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.
--
Steve Walton

Feb 21 '07 #1
2 2696
Hi,

"Steve Walton" <No****@NoSpam. comwrote in message
news:d3******** *************** *********@4ax.c om...
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(AddressF amily.InterNetw ork,SocketType. Stream,Protocol Type.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 InternalExcepti on ?
Feb 21 '07 #2
"Steve Walton" <No****@NoSpam. comwrote
[...]
Now, we are trying to use these
applications at another site and we get an exception on the following
line:-

Socket oRequest = new
Socket(AddressF amily.InterNetw ork,SocketType. Stream,Protocol Type.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?
--
Chris Mullins, MCSD.NET, MCPD:Enterprise , Microsoft C# MVP
http://www.coversant.com/blogs/cmullins
Feb 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4221
by: Russell Warren | last post by:
Does anyone know the scope of the socket.setdefaulttimeout call? Is it a cross-process/system setting or does it stay local in the application in which it is called? I've been testing this and it seems to stay in the application scope, but the paranoid side of me thinks I may be missing something... any confirmation would be helpful.
4
8718
by: DreJoh | last post by:
I've read many articles on the subject and the majority of them give the same solution that's in article 821625 on the MSDN website. I'm using the following code and when a the client disconnects the child socket remains in the CLOSE_WAIT state. Anyone have any idea what's missing? ----------------------------- Socket Code ----------------------------- namespace Sockets { #region Class - SocketClient
3
4623
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, I use the System.Net.Sockets to send/receive data (no tcpclient/tcplistener), I made a receivethread in my wrapper, the receivethread loops/sleeps while waiting for data and then fires a datareceived event. Within the waitingloop there is a timeout function, but I want the the 'last-time-socket-used' variable set when the socket is finished sending. When I send by System.Net.Sockets.Socket.Send(buffer()) (<--this...
2
702
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no more data to expect). Sometimes, Socket.Available returns 0 but the other end of the connection did not close it ! 2) This class will be used by many other classes so I have to use the
2
4146
by: Nuno Magalhaes | last post by:
I've got a simple problem I guess. How do I know when a connection is terminated without losing any data? I do something like the code below, but sometimes between socket.Receive and socket.Send I get the last chunk of data and am not able to retrieve it anymore cause the socket will be dead. Loop: { socket.Receive <----------- data arrives
11
7704
by: hazz | last post by:
smtpClient.Send(message) is causing me problems as per specifics in the trace below. Email is sent but not without this error typically upon sending the second email, but sometimes when running the app, even the first time. The application will be required to be sending out repeated emails, about one every second or two. Must this be done asynchronously? Thank you. -Greg I get the generic error messages;
10
3564
by: John Nagle | last post by:
Here are three network-related exceptions. These were caught by "except" with no exception type, because none of the more specific exceptions matched. This is what a traceback produced: 1. File "D:\Python24\lib\socket.py", line 295, in read data = self._sock.recv(recv_size) timeout: timed out
3
14399
by: Cheryl | last post by:
Hi. I am having a problem on handling asynchronous sockets in C#. I implemented a pair of client and server sockets. The connection is ok when first connected. However, when I turned off the server socket, the client is able to connect, but cannot send anything out. It seems that the Socket.Connected is false but I received no disconnection event. Any idea on how to solve the problem? Thanks.
2
3663
by: manasap | last post by:
Hi all! I've written a server and a client application using asynchronous sockets.The client sends data packets for every 7 seconds.The server receives the packets. This process proceeds smoothly without any errors but,sometimes I get the following error. "An existing connection was forcibly closed by the remote host." Why is this happening when i am not closing the client program? Could someone guide me in this issue
0
8236
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8173
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8679
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.