Socket send problem!

  • Thread starter Thread starter Tomer
  • Start date Start date
T

Tomer

Hi,

I've used the Wintalk sample in order to write a pocket pc client application that sends data to a server through a GPRS connection.

I'm sending the contents of a table, so I have a loop that runs on the table and sends for each row a string through the socket.
About 1 out of 3 times the application get stuck entirely during this loop.
When I'm work on WLAN everything work just fine.

I've tried 3 different ways the send the data through the socket but got the same result.

Here's the code:

(blocking is set to true)
public void SendData(String Data)

{

// ========== one way

SendDataBytes = Encoding.ASCII.GetBytes(Data.ToCharArray());

stream.Write(SendDataBytes,0,SendDataBytes.Length);

stream.Flush();

Thread.Sleep(this.delayBetweenTransmittions); // little delay between sends

// ========== another way that 'worked' the same way

SendDataBytes = Encoding.ASCII.GetBytes(Data.ToCharArray());

socket.Send(SendDataBytes,SendDataBytes.Length,SocketFlags.None);

Thread.Sleep(this.delayBetweenTransmittions); // little delay between sends

// =========== 3rd way that 'worked' the same way

writer.Write(Data);

writer.Flush();

Thread.Sleep(this.delayBetweenTransmittions); // little delay between sends

}



Please help!



Tomer.
 
Hi Tomer,

You are using blocking methods. So these methods will not return until they
accomplish the goal or generate and error.

If you call this method from an method which handles an event, your
application's message queue will be blocked until you return from this
method.

Are you calling this method from an event handling method without creating
a child thread?

Thanks

Ercan Turkarslan
Microsoft Mobile Devices Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Ercan,

Like in the WinTalk application, we do have event handler, and the function
EstablishSocket is being run withc this line:
ThreadPool.QueueUserWorkItem(new WaitCallback(EstablishSocket));

but the send/receive does run on a seperate thread.

I'm a little new to threading , so could you give an example on how do I
handle this with threading?


Tomer.
 
Hi Ercan,
By the way, I don't think that my application waits for the send to return,
only because I'm using a timer to monitor the time difference between each
send/receive, if the difference is bigger than 10 second I abort the
connection.
But when the loop get stuck the timer also get stuck, I know this because
I'm playing a sound each timer ticks.
So that must means that the application is stuck and not waiting for a
function to return.

Tomer.
 
Hi Tomer,

Does the behavior change when you increase the timeout?

Could you also try waiting 2 minutes after you about a connection? On Win
CE it may take 2 minutes to unblock the socket.

Thanks

Ercan Turkarslan [MSFT]
Microsoft Mobile Devices Developer Support

(e-mail address removed)


This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top