vs2005+tcp over usb/activesync 4.2 error: existing connection forcibly closed

A

adiel_g

Environment: vs2005+tcp over usb using activesync 4.2

Application: vs2005 pocket pc application using System.Net.Sockets

Hardware: Ipaq 3850 running pocket pc 2003

I am receiving an error: "An existing connection was forcibly closed by
the remote host" when using system.net.sockets:

Dim ipAddress As IPAddress = ipAddress.Parse(serverIp)

Dim remoteEP As New IPEndPoint(ipAddress, 11000)

' Create a TCP/IP socket.
Dim sender As New Socket(AddressFamily.InterNetwork, _
SocketType.Stream, ProtocolType.Tcp)

' Connect the socket to the remote endpoint.
sender.Connect(remoteEP) '<--connect works fine, no errors

' Encode the data string into a byte array.
Dim msg As Byte() = Encoding.ASCII.GetBytes(strDataToSend & "<EOF>")

' Send the data through the socket.
Dim bytesSent As Integer = sender.Send(msg) '<-- here is the error
line


The error comes at the call to the "sender.Send..." method. If I run
the application from the pocket pc emulator, it works fine. After much
research the problem seems to be related to TCP over USB using
activesync 4.2 but I have yet to find a solution.

Thanks Before Hand,
Adiel
 
C

Chris Oswald

I have received a similar error when working with sockets. My solution
was to make sure the LingerOption was turned on.
 
A

adiel_g

Here is the update:

I am now turning the linger option ON. I am doing so right BEFORE the
connect in the
pocket pc code:

Dim lingerOption As LingerOption = New LingerOption(True, 1)
sender.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Linger, lingerOption)


' Connect the socket to the remote endpoint.
sender.Connect(remoteEP)

The first attempt returned the same error "..existing connection
forcibly closed.."
The second attempt sent the data using this line of code:

Dim bytesSent As Integer = sender.Send(msg)

But then went into an infinite loop in the ..sender.Receive.. since no
data was received.

The third attempt went back to "..existing connection forcibly
closed..".

Basically sometimes the first error would happen, sometimes the second
error would happen.

Thanks Again,
Adiel
 
C

Chris Oswald

You may try extending the time on the linger to 5 seconds instead of 1.
Do you have Keep Alives on the device you are talking to. If so turn
those off.
 

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