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

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". The error only happens with fairly
large amounts of data (around 24,500 bytes).

VB .NET 2003, Pocket PC 2003, CF 1.0 SP 2

Can anyone help with this problem?
 
M

Mike

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)
 
M

Mike

{System.Net.Sockets.SocketException}

ErrorCode: 10054

InnerException: Nothing

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

NativeErrorCode: 10054
 
M

Mike

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.
 
R

Rashmi Anoop[MSFT]

Hi Mike,

I'm looking into this issue right now and will reply to you as soon as
possible.

Regards,
Rashmi.
This posting is provided "AS IS", with no warranties, and confers no rights.
 
R

Rashmi Anoop[MSFT]

I tested your code snippet with webproxy object . Its not throwing
exceptions at all. It is working. Are you seeing this problem only on
device or emulator or both?

Regards,
Rashmi.

This post is provided "AS IS" , with no warranties, and confers no rights.
 

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