473,395 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

synchronous socket connection closed error

I got the following error when revieving data from a server.

hostSystem.Net.Sockets.SocketException: An existing connection was forcibly
closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[]
buffer, Int32 offset, Int32 size, SocketFlags socketFlags)

This error only happens when the long time recieving data, in this case 50
seconds. It looks to me like a time out error.

I have an j++ application which does the same thing but can revieve data
without any problem.

Code:
createSockConnection();
sock.Blocking = true;
sock.NoDelay = true;
sock.ReceiveTimeout = 10000000;

byte[] readBytes = new byte[1024];
Int32 sizeReceived = 0;

WebHeaderCollection Headers = new WebHeaderCollection();

while ((sizeReceived = sock.Receive(readBytes, readBytes.Length,
SocketFlags.None)) > 0)
{
nTotalBytes += sizeReceived;
ResponseText.Write(readBytes, 0, sizeReceived);
}

Please help.

thanks

Kevin Yang

May 16 '06 #1
4 5843
IIRC, you will get that error when the remote host closes the socket on
timeout or other. Is the client Receive not being posted for a long period?
If you own the server, you could increase the send/receive timeout to find
the right mix. But it sounds more like you have erroneous delays as the
client side.

--
William Stacey [MVP]

"Kevin" <Ke***@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
|I got the following error when revieving data from a server.
|
| hostSystem.Net.Sockets.SocketException: An existing connection was
forcibly
| closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[]
| buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
|
| This error only happens when the long time recieving data, in this case 50
| seconds. It looks to me like a time out error.
|
| I have an j++ application which does the same thing but can revieve data
| without any problem.
|
| Code:
| createSockConnection();
| sock.Blocking = true;
| sock.NoDelay = true;
| sock.ReceiveTimeout = 10000000;
|
| byte[] readBytes = new byte[1024];
| Int32 sizeReceived = 0;
|
| WebHeaderCollection Headers = new WebHeaderCollection();
|
| while ((sizeReceived = sock.Receive(readBytes, readBytes.Length,
| SocketFlags.None)) > 0)
| {
| nTotalBytes += sizeReceived;
| ResponseText.Write(readBytes, 0, sizeReceived);
| }
|
| Please help.
|
| thanks
|
| Kevin Yang
|
|
|
May 16 '06 #2
I connect to a slow server which I don't have control. Is that possible the
server closes it's connection after it send out the whole data, but client
side have not received it yet?

The server is slow but it still works. I have a socket based J++ application
which works perfectly for 3 years. Now I want to upgrade it to c# and I got
this problem.

The exception was triggered when I received about half of the data, and this
happens every time.

I do believe the server does not close its connection otherwise the j++ code
will not work as well.

Other than sock.ReceiveTimeout, anywhere else I can set tcp time out property?

Thanks

Kevin Yang

"William Stacey [MVP]" wrote:
IIRC, you will get that error when the remote host closes the socket on
timeout or other. Is the client Receive not being posted for a long period?
If you own the server, you could increase the send/receive timeout to find
the right mix. But it sounds more like you have erroneous delays as the
client side.

--
William Stacey [MVP]

"Kevin" <Ke***@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
|I got the following error when revieving data from a server.
|
| hostSystem.Net.Sockets.SocketException: An existing connection was
forcibly
| closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[]
| buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
|
| This error only happens when the long time recieving data, in this case 50
| seconds. It looks to me like a time out error.
|
| I have an j++ application which does the same thing but can revieve data
| without any problem.
|
| Code:
| createSockConnection();
| sock.Blocking = true;
| sock.NoDelay = true;
| sock.ReceiveTimeout = 10000000;
|
| byte[] readBytes = new byte[1024];
| Int32 sizeReceived = 0;
|
| WebHeaderCollection Headers = new WebHeaderCollection();
|
| while ((sizeReceived = sock.Receive(readBytes, readBytes.Length,
| SocketFlags.None)) > 0)
| {
| nTotalBytes += sizeReceived;
| ResponseText.Write(readBytes, 0, sizeReceived);
| }
|
| Please help.
|
| thanks
|
| Kevin Yang
|
|
|

May 16 '06 #3
I found the cause.

After I removed line "sock.Shutdown(SocketShutdown.Send);", everything works
fine.

I seems the server have problem to handle this shutdown send.

thanks for your reply.

Kevin Yang
"William Stacey [MVP]" wrote:
IIRC, you will get that error when the remote host closes the socket on
timeout or other. Is the client Receive not being posted for a long period?
If you own the server, you could increase the send/receive timeout to find
the right mix. But it sounds more like you have erroneous delays as the
client side.

--
William Stacey [MVP]

"Kevin" <Ke***@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
|I got the following error when revieving data from a server.
|
| hostSystem.Net.Sockets.SocketException: An existing connection was
forcibly
| closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[]
| buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
|
| This error only happens when the long time recieving data, in this case 50
| seconds. It looks to me like a time out error.
|
| I have an j++ application which does the same thing but can revieve data
| without any problem.
|
| Code:
| createSockConnection();
| sock.Blocking = true;
| sock.NoDelay = true;
| sock.ReceiveTimeout = 10000000;
|
| byte[] readBytes = new byte[1024];
| Int32 sizeReceived = 0;
|
| WebHeaderCollection Headers = new WebHeaderCollection();
|
| while ((sizeReceived = sock.Receive(readBytes, readBytes.Length,
| SocketFlags.None)) > 0)
| {
| nTotalBytes += sizeReceived;
| ResponseText.Write(readBytes, 0, sizeReceived);
| }
|
| Please help.
|
| thanks
|
| Kevin Yang
|
|
|

May 16 '06 #4
That would seem to be a bug on the server side. I assume the server is
async so when it reads a shutdown, it closes the socket before all sends are
finished. On the other hand, this may be the protocol the server expects.
Glad you found it.

--
William Stacey [MVP]

"Kevin" <Ke***@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
|I found the cause.
|
| After I removed line "sock.Shutdown(SocketShutdown.Send);", everything
works
| fine.
|
| I seems the server have problem to handle this shutdown send.
|
| thanks for your reply.
|
| Kevin Yang
|
|
| "William Stacey [MVP]" wrote:
|
| > IIRC, you will get that error when the remote host closes the socket on
| > timeout or other. Is the client Receive not being posted for a long
period?
| > If you own the server, you could increase the send/receive timeout to
find
| > the right mix. But it sounds more like you have erroneous delays as the
| > client side.
| >
| > --
| > William Stacey [MVP]
| >
| > "Kevin" <Ke***@discussions.microsoft.com> wrote in message
| > news:3D**********************************@microsof t.com...
| > |I got the following error when revieving data from a server.
| > |
| > | hostSystem.Net.Sockets.SocketException: An existing connection was
| > forcibly
| > | closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[]
| > | buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
| > |
| > | This error only happens when the long time recieving data, in this
case 50
| > | seconds. It looks to me like a time out error.
| > |
| > | I have an j++ application which does the same thing but can revieve
data
| > | without any problem.
| > |
| > | Code:
| > | createSockConnection();
| > | sock.Blocking = true;
| > | sock.NoDelay = true;
| > | sock.ReceiveTimeout = 10000000;
| > |
| > | byte[] readBytes = new byte[1024];
| > | Int32 sizeReceived = 0;
| > |
| > | WebHeaderCollection Headers = new WebHeaderCollection();
| > |
| > | while ((sizeReceived = sock.Receive(readBytes, readBytes.Length,
| > | SocketFlags.None)) > 0)
| > | {
| > | nTotalBytes += sizeReceived;
| > | ResponseText.Write(readBytes, 0, sizeReceived);
| > | }
| > |
| > | Please help.
| > |
| > | thanks
| > |
| > | Kevin Yang
| > |
| > |
| > |
| >
| >
| >
May 17 '06 #5

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

Similar topics

1
by: Joe | last post by:
Hi, I browsed the news and a few seem to have this problem too, but no solution ! I have a client server application where in case the connection gets bad (crashes or whatever) client or...
1
by: Dr. J | last post by:
I have an application that opens a socket and connects to another application listening over a port. The problem I am encountering is that when the listening application is closed my application...
2
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...
2
by: Rene Sørensen | last post by:
We are 4 students working on a assignment, that our teacher gave use, normally we do this is C++, but the 4 of us, use C# more often that C++ so… We made a small games called reversi, now our job...
4
by: schwehr | last post by:
Hi All, I've tried to RTFM this and am having no luck. First off, I am using Mac OSX 10.4.7 with python 2.4.2 from fink. I am trying to connect to a server that should be rejecting...
1
by: Mr. Beck | last post by:
Hello, Please Help..... I have been working with some tcp/ip socket communication within a C# program recently. Basicly, I have a program (myProblemProgram) that has a socket connected to...
5
by: Arno | last post by:
reposted with the right microsoft managed newsgroup ID: Sorry for the inconvinience Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable...
5
by: Navin Mishra | last post by:
Hi, In load test of our .NET 2.0 socket application on Win2003 server, we are seeing sometimes WSEWOULDBLOCK error when sending data to clients. We are using synchronoous scokets with...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.