Socket.BeginConnect works in Synchronous mode!!!!!!!!

L

leon

Hi
Strangest thing happened, the asynchronous command
Socket.BeginConnect, start behave in a Synchronous !!!!
mode.

Here some code:

try
{
_CountPackets = 0;

IPAddress ipAddress =
Dns.GetHostEntry(IpServer).AddressList[0];

_IpEndpoint = new IPEndPoint(ipAddress, PortServer);

_ClientSocket = new Socket(
AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);

IAsyncResult asyncConnect =
_ClientSocket.BeginConnect(
_IpEndpoint,
new AsyncCallback(ConnectCallback),
_ClientSocket);

}
catch (Exception exc)
{
CloseSocket();
}

The same code(_ClientSocket.BeginConnect) runs in Asynchronous!!! mode
on a different machine.

Does any one know what is all about ?
thanks
 
H

Henning Krause [MVP - Exchange]

Hello,

how do you check whether beginconnect runs synchrnonous?

Kind regards,
Henning Krause
 
P

Peter Duniho

Strangest thing happened, the asynchronous command
Socket.BeginConnect, start behave in a Synchronous !!!!
mode.

What does that mean? Are you saying that BeginConnect() blocks until a
connection has been completed? That it doesn't return until after your
ConnectCallback() method has been called and has itself returned?

If not, you need to explain your question more clearly.

If so, what OS are you using? The Socket asynchronous methods use IOCP,
but .NET runs on some Windows versions that don't support IOCP. I suppose
it's possible that in that case, the asynchronous methods might behave in
a more synchronous manner.

Pete
 
L

leon

What does that mean?  Are you saying that BeginConnect() blocks until a  
connection has been completed?  That it doesn't return until after your  
ConnectCallback() method has been called and has itself returned?

If not, you need to explain your question more clearly.

If so, what OS are you using?  The Socket asynchronous methods use IOCP, 
but .NET runs on some Windows versions that don't support IOCP.  I suppose  
it's possible that in that case, the asynchronous methods might behave in  
a more synchronous manner.

Pete

Thanks for the replies,
first of all, i figured that the BeginConnect works differently only
if timeout exception is thrown(if the device is connected to LAN the
command works properly - Asynchronously )
secondly there are two machines i'm working on, the first machine is
processing correctly and when the exception is thrown the callback
thread handles it.
On the second machine the timeout exception is thrown in the main
thread(which called the BeginConnect). BeginConnect call blocks the
thread from advance to the next line until the timeout exception
occurs in the mainthread (the callback method is never called).
Both machines work on the exact same code.
Both the machines i work on have WinXp sp2 installed. I develop with
VS2008 (framework 3.5).
 
P

Peter Duniho

[...]
On the second machine the timeout exception is thrown in the main
thread(which called the BeginConnect). BeginConnect call blocks the
thread from advance to the next line until the timeout exception
occurs in the mainthread (the callback method is never called).
Both machines work on the exact same code.

How long is the timeout? Are you sure that the thread waits for the
entire timeout period? Have you measured the actual time that the
BeginConnect() call takes using the Stopwatch class or similar?

I've never heard of a "Begin..." method blocking. I would consider it a
bug for it to do so. But first you should double-check to make sure it's
really blocking, rather than detecting an exception condition immediately
and throwing the exception. Why that would happen with a timeout
exception, I don't know, especially on the most recent .NET version (I
could see if there was a version difference in the installed .NET on each
machine, but your post implies you're using 3.5 on both).

Pete
 
L

leon

[...]
On the second machine the timeout exception is thrown in the main
thread(which called the BeginConnect). BeginConnect call blocks the
thread from advance to the next line until the timeout exception
occurs in the mainthread (the callback method is never called).
Both machines work on the exact same code.

How long is the timeout?  Are you sure that the thread waits for the  
entire timeout period?  Have you measured the actual time that the  
BeginConnect() call takes using the Stopwatch class or similar?

I've never heard of a "Begin..." method blocking.  I would consider it a 
bug for it to do so.  But first you should double-check to make sure it's  
really blocking, rather than detecting an exception condition immediately  
and throwing the exception.  Why that would happen with a timeout  
exception, I don't know, especially on the most recent .NET version (I  
could see if there was a version difference in the installed .NET on each  
machine, but your post implies you're using 3.5 on both).

Pete


Thank you all,
the problem is been fixed by reinstalling SP2.!!!!!

Have a good day
 

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