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

M

Mike

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

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


Here is ToString() of the exception object raised:

{System.Net.Sockets.SocketException}

ErrorCode: 10054

InnerException: Nothing

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

NativeErrorCode: 10054
------------------------------------------------------------

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

John Eikanger [MSFT]

Hi, Mike

Tian Huang and others posted responses in microsoft.public.dotnet.framework.

Posting multiple messages in this way is called multi-posting, which is
considered poor manners in the newsgroups and will get you flamed if some
people notice. This is because an answer to one post is not available in
the other. If I answer your question in one thread and it was already
answered in another thread, I've wasted my time. The preferred technique
is called crossposting, which puts linked copies of the same post in
multiple newsgroups.. You can crosspost using Outlook Express or the MSDN
Web interface by explicitly typing the names of the groups (separated by
semi-colons) in the Newsgroup box that appears when you post.

Example: microsoft.public.vb.com;microsoft.public.vb.database.ado etc.

HTH,

John Eikanger
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.
(c) 2004 Microsoft Corporation. All rights reserved.
--------------------
| From: "Mike" <[email protected]>
| Subject: "An existing connection was forcibly closed by the remote host"
| Date: Fri, 5 Mar 2004 11:55:32 -0500
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| VB .NET 2003, Pocket PC 2003, CF 1.0 SP 2
|
| 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).
|
|
| Here is ToString() of the exception object raised:
|
| {System.Net.Sockets.SocketException}
|
| ErrorCode: 10054
|
| InnerException: Nothing
|
| Message: "An existing connection was forcibly closed by the remote host"
|
| NativeErrorCode: 10054
| ------------------------------------------------------------
|
| 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)
|
|
|
|
 

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