473,804 Members | 3,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

synchronous socket connection closed error

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

hostSystem.Net. Sockets.SocketE xception: An existing connection was forcibly
closed by the remote host at System.Net.Sock ets.Socket.Rece ive(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:
createSockConne ction();
sock.Blocking = true;
sock.NoDelay = true;
sock.ReceiveTim eout = 10000000;

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

WebHeaderCollec tion Headers = new WebHeaderCollec tion();

while ((sizeReceived = sock.Receive(re adBytes, readBytes.Lengt h,
SocketFlags.Non e)) > 0)
{
nTotalBytes += sizeReceived;
ResponseText.Wr ite(readBytes, 0, sizeReceived);
}

Please help.

thanks

Kevin Yang

May 16 '06 #1
4 5867
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***@discussi ons.microsoft.c om> wrote in message
news:3D******** *************** ***********@mic rosoft.com...
|I got the following error when revieving data from a server.
|
| hostSystem.Net. Sockets.SocketE xception: An existing connection was
forcibly
| closed by the remote host at System.Net.Sock ets.Socket.Rece ive(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:
| createSockConne ction();
| sock.Blocking = true;
| sock.NoDelay = true;
| sock.ReceiveTim eout = 10000000;
|
| byte[] readBytes = new byte[1024];
| Int32 sizeReceived = 0;
|
| WebHeaderCollec tion Headers = new WebHeaderCollec tion();
|
| while ((sizeReceived = sock.Receive(re adBytes, readBytes.Lengt h,
| SocketFlags.Non e)) > 0)
| {
| nTotalBytes += sizeReceived;
| ResponseText.Wr ite(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.ReceiveTim eout, 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***@discussi ons.microsoft.c om> wrote in message
news:3D******** *************** ***********@mic rosoft.com...
|I got the following error when revieving data from a server.
|
| hostSystem.Net. Sockets.SocketE xception: An existing connection was
forcibly
| closed by the remote host at System.Net.Sock ets.Socket.Rece ive(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:
| createSockConne ction();
| sock.Blocking = true;
| sock.NoDelay = true;
| sock.ReceiveTim eout = 10000000;
|
| byte[] readBytes = new byte[1024];
| Int32 sizeReceived = 0;
|
| WebHeaderCollec tion Headers = new WebHeaderCollec tion();
|
| while ((sizeReceived = sock.Receive(re adBytes, readBytes.Lengt h,
| SocketFlags.Non e)) > 0)
| {
| nTotalBytes += sizeReceived;
| ResponseText.Wr ite(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***@discussi ons.microsoft.c om> wrote in message
news:3D******** *************** ***********@mic rosoft.com...
|I got the following error when revieving data from a server.
|
| hostSystem.Net. Sockets.SocketE xception: An existing connection was
forcibly
| closed by the remote host at System.Net.Sock ets.Socket.Rece ive(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:
| createSockConne ction();
| sock.Blocking = true;
| sock.NoDelay = true;
| sock.ReceiveTim eout = 10000000;
|
| byte[] readBytes = new byte[1024];
| Int32 sizeReceived = 0;
|
| WebHeaderCollec tion Headers = new WebHeaderCollec tion();
|
| while ((sizeReceived = sock.Receive(re adBytes, readBytes.Lengt h,
| SocketFlags.Non e)) > 0)
| {
| nTotalBytes += sizeReceived;
| ResponseText.Wr ite(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***@discussi ons.microsoft.c om> wrote in message
news:EC******** *************** ***********@mic rosoft.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***@discussi ons.microsoft.c om> wrote in message
| > news:3D******** *************** ***********@mic rosoft.com...
| > |I got the following error when revieving data from a server.
| > |
| > | hostSystem.Net. Sockets.SocketE xception: An existing connection was
| > forcibly
| > | closed by the remote host at System.Net.Sock ets.Socket.Rece ive(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:
| > | createSockConne ction();
| > | sock.Blocking = true;
| > | sock.NoDelay = true;
| > | sock.ReceiveTim eout = 10000000;
| > |
| > | byte[] readBytes = new byte[1024];
| > | Int32 sizeReceived = 0;
| > |
| > | WebHeaderCollec tion Headers = new WebHeaderCollec tion();
| > |
| > | while ((sizeReceived = sock.Receive(re adBytes, readBytes.Lengt h,
| > | SocketFlags.Non e)) > 0)
| > | {
| > | nTotalBytes += sizeReceived;
| > | ResponseText.Wr ite(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
6139
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 server (who knows it first) closes the socket and than wants to establish the SAME connection again ( due to firewall reasons it has to be the SAME IP AND PORT).
1
16470
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 cannot detect it to take appropriate action. I am using "Connected" property of the Socket class, but it seems this property does not reflect the true state of the socket connection. Here is the code snippet. Basically, I am checking the...
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
2881
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 is to make a server, none of us know nothing about socket programming in C#, but we founds some guides for this, and now ,got a server running, but we have some problems though. We have 2 scenario, one where we use a telnet connection and one...
4
5234
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 connections and I was surprised when it did not throw an exception or do something otherwise equally nasty. It just connects and never returns any data. First, the proof that something is there and rejecting the connection (or is it that this thing...
1
17552
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 another program for information passing. Upon receiving a particular "command" from the the information passing program, myProblemProgram will launch a separate thread to do individual communication with another file transfer program. The thread...
5
15732
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 to read data from the transport connection" when restart reading the stream with socket.BeginRead in the Sub SocketIncomingMsg. I'm debugging now for weeks, but I can't detect where it's
5
1829
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 SendTimout of 2 secs. Is it normal ? Thanks in advance and regards Navin
0
9706
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
10578
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...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10077
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9152
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6853
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
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.