"An existing connection was forcibly closed by the remote host"

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Only when I use a proxy server, I'm getting this error when attempting to
write data to a Stream object from an HTTPWebRequest object.
(System.IO.Stream.Write() raises the exception):"An existing connection was
forcibly closed by the remote host"
VB .NET 2003, Pocket PC 2003, CF 1.0 SP 2

Can anyone help with this problem?
 
Here is ToString() of the exception object raised:

{System.Net.Sockets.SocketException}

[System.Net.Sockets.SocketException]: {System.Net.Sockets.SocketException}

InnerException: Nothing

Message: "An existing connection was forcibly closed by the remote host"
------------------------------------------------------------

Here is the code:

Dim myRequest As System.Net.HttpWebRequest

Dim myResponse As System.Net.WebResponse

Dim myProxy As New System.Net.WebProxy

Dim bPostData() As Byte

Dim sPost As String

Dim Stream1 As System.IO.Stream

Dim newUri As System.Uri

sPost = StrDup(25000, "X")

Cursor.Current = Cursors.WaitCursor

myRequest = System.Net.WebRequest.Create("http://server.com/file.php")

myRequest.Timeout = 30000

myProxy = New System.Net.WebProxy

newUri = New Uri("http://192.168.2.36:4480")

' Associate the new Uri object to the myProxy object.

myProxy.Address = newUri

myProxy.Credentials = New System.Net.NetworkCredential("admin", "admin")

myRequest.Proxy = myProxy

myRequest.Method = "POST"

myRequest.ContentType = "application/x-www-form-urlencoded"

' Encode the data

bPostData = System.Text.Encoding.UTF8.GetBytes(sPost)

myRequest.ContentLength = bPostData.Length

' must buffer request for authentication

myRequest.AllowWriteStreamBuffering = True

Try

' Write encoded data into request stream

Stream1 = myRequest.GetRequestStream()

Stream1.Write(bPostData, 0, bPostData.Length)
 
{System.Net.Sockets.SocketException}

ErrorCode: 10054

InnerException: Nothing

Message: "An existing connection was forcibly closed by the remote host"

NativeErrorCode: 10054
 
Weird. I get the exact same exception if the Proxy server isn't even
running.
Code works fine if I don't use a WebProxy object.
 
Hi Mike,

Do you use ActiveSync? What is the version of ActiveSync do you use?
There is code defect in ActiveSync 3.7 cause the issue, and this has been
fixed in 3.7.1.

Jimmy Zhu
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
I'm using ActiveSync v3.7.1 Build 3244

Could you post a link that shows this was a bug in ActiveSync v3.7?
 
Hi Mike,

It looks like your question is not the same one I mentioned last time.

The native error 10054 - WSAECONNRESET:
"Connection reset by peer.
An existing connection was forcibly closed by the remote host. This
normally results if the peer application on the remote host is suddenly
stopped, the host is rebooted, the host or remote network interface is
disabled, or the remote host uses a hard close (see setsockopt for more
information on the SO_LINGER option on the remote socket). This error may
also result if a connection was broken due to keep-alive activity detecting
a failure while one or more operations are in progress. Operations that
were in progress fail with WSAENETRESET. Subsequent operations fail with
WSAECONNRESET."

Are you sure the proxy server works correctly? If so, you may need to
capture the network packages by using netmon.exe and to see what happens on
earth.

Jimmy Zhu
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
I don't think the proxy server was involved - the problem occurred even when
I turned the proxy server off before starting the process. I believe the
problem is buffering on the device. You have to turn buffering on on the
HTTPWebRequest object to use a proxy server, and it is when buffering is
turned on that the problem occurred. Also, the problem only occurred when I
tried to send more than 25,000 bytes of data. Because of this, I think it
was a memory issue on the device.

You should be able to reproduce the problem if you have a device using the
code I posted.
 
Hi Mike,

I'll be assisting you with this issue. This question has been cross posted
under Compactframework too. I'll be replying with my findings under
compactframework and will close this one out.

Regards,
Rashmi.
 
Hello Mike,

As Rashmi's reply mentioned, he has followed up this question in
Compactframework newsgroup since this question has been cross posted there.
Have you checked the reply there?

If there is any question on it, please feel free to post there and he will
follow up you in that thread. Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Yes I checked the reply there. Did you check the reply there? He made one
post on March 9 and hasn't posted since.

There are bugs in the Pocket PC software. Someone at Microsoft please
reproduce these bugs using a Pocket PC device and the code I have provided
and start working on fixing the problems.
 
Hi Mike,

What I meant is that Rashmi is working with you on it in that thread. It is
better to post a reply there to ask him the issue status. So we can better
track the issue to make sure one engineer is working with you. Also,
Rashimi replied you there on 3/26 already.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top