Socket gets disconnected on Win CE device

Spek

Member
Joined
Nov 6, 2009
Messages
10
Programming Experience
Beginner
Hi,

I'm having some problems with TCP sockets in a VB.net application running on a Windows CE mobile device. The program connects with another Delphi (Indy) Server application and then sends/requests data simply by sending byte array's. Each packet is 256 bytes. If I need to send more, I just send multiple packets.

This works, however, quite often the connection just suddenly dies when sending something. When I need to send a large amount of data (~100 kb for example), I can see the WiFi connection on the device looses its signal sometimes, and the connection will break.

My first guess was that the program utilizes the device for 100% so other background processes (like keeping up the WiFi connection?) will
get blocked for too long. So I simply added some sleep:
VB.NET:
	' BTW Sending happens inside the main program thread
	while packetsAvailable 
	   tcpClient.send( byteArray )  ' 256 bytes

	   < check if there is more data to send >
	   ...
	   Threading.Thread.Sleep(8)
	end while
Adding this delay helps alot, but still I get disconnected sometimes. I could increase the sleeptime but it will make sending data slow. These mobile devices are no supercomputers of course, but I doubt if this is the way to go.

The program also runs 1 "listener" thread (priority=normal, background=true). This thread will check if there was something received from the server. This is done via the *same* TCPclient...
VB.NET:
private sub pollData
	while true do
		Threading.Thread.Sleep(5)
		Try
			tcpClient.Receive(packet)	' Fill array of bytes[256]
		Catch e As Exception		
			msgBox ...
			return
		end try
	            
		< do something with the data >
	end while
Although I won't receive anything while sending, I can imagine these 2 processes might hurt each other.

Regards,
Rick
 
Back
Top