Socket connect so slow first time?

G

Guest

Hi,

I am new to socket connection on CF2.0

I am developing an application that runs on PocketPC 2003, using sockets it
connects to a desktop PC.

However everytime I start a connection, it takes about 10-15 seconds to get
connected before i can send data out......this is a long wait.

But this problem only happens if it is run for the first time, or if u leave
it disconnected for a period of time and re-connect again.

Here is my connection code:
' Resolve the name to an IP Address
Dim Addr As IPAddress = Dns.GetHostEntry(DNSname).AddressList(0)

If Not Addr Is Nothing Then
' Create an IP Endpoint
Dim EP As New IPEndPoint(Addr, CInt(DNSport))
' Create a new socket
clientSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
' Connect
clientSocket.BeginConnect(EP, AddressOf ConnectCallback, Nothing)

Dim nowSec As Double = Microsoft.VisualBasic.DateAndTime.Timer

' wait for connection
Do While clientSocket.Connected = False
' Wait to be connected otherwise timeout
If Microsoft.VisualBasic.DateAndTime.Timer - nowSec > 20 Then
Exit sub
End If
Loop
End If

Any help please?

Many thanks in advance!
 
P

Paul G. Tobey [eMVP]

You haven't told us anything about the network structure! *How is the
device connected to the PCs network*?

Paul T.
 
S

Simon Hart

I've never had an issue with this I must say.

The desktop PC, this is presumably your development machine? and I take it
its local. How are you connecting, ActiveSync etc...
 
G

Guest

Sorry i didn't mention about the network structure..... here it is:

PocketPC connect wireless to router (no built-in firewall).
Wireless router connected via uplink to ethernet LAN hub.
Desktop PC connected to LAN hub.

The Desktop PC is running Windows Firewall on the Lan card, but the port
which use for the socket added into exceptions.
 
P

Paul G. Tobey [eMVP]

I've definitely never seen that happen, whether over wireless or not. Is
the wireless connection well-established before you try to make your
outgoing connection or might it be performing some type of EAP exchange to
verify who your device is? That's really all I can think of. You can run a
sniffer on the PC and see how long it's taking to reply to the request for
connection...

Paul T.
 
G

Guest

Thanks for the reply.

The wireless is always ON, connected to the router.
For the socket, i only make a connection when i need to request something, i
then disconnect it when i finish.

Could that be the problem on my server side?

here is my Listener code:

' Get hostname into IP address
'Dim str As String =
Dns.GetHostByName(Dns.GetHostName).AddressList(0).ToString
Dim str As String = Dns.GetHostEntry(Dns.GetHostName).AddressList(0).ToString
Dim ip As IPAddress = IPAddress.Parse(str)

mobjListener = New TcpListener(ip, pb_ServerPDAPort)
mobjListener.Start()
Do
Dim x As New cllpClient(mobjListener.AcceptTcpClient)

AddHandler x.Connected, AddressOf OnConnected ' change Label text
AddHandler x.Disconnected, AddressOf OnDisconnected ' change Label text
AddHandler x.LineReceived, AddressOf OnLineReceived ' change Label text

' Force main thread update
'Me.Invoke(New StatusInvoker(AddressOf Me.UpdateStatus), params)
Loop Until False

Many thanks.
 
P

Paul G. Tobey [eMVP]

Well, I suppose it could be a problem. If you need the highest level of
responsiveness (the user is sitting there waiting for something and your
application can't continue until you get a response), you'd be better off
leaving the socket open, after the first connect, I'd think. I'd say it's
about 50/50 right now whether this is something you're doing to yourself or
something imposed from outside. You might try connecting the Windows CE
device to the wired Ethernet, rather than wireless and see what that does.
You should also check to be sure that there's not an alternate path to the
same subnet that the network traffic might be taking in error (if you have
two ways of getting to the network, for example).

Paul T.
 
G

Guest

Thanks for your advice and help, i will looking into it.

At least now i know it is not a normal behaviour of the socket, there is
something wrong else where.

Cheers.
Jon
 

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