SilverLight Socket Issue
I'm trying write a silverlight application, socket can connect to 127.0.0.1:4505 but arg.completed event doesn't work
arg.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, 4505);
arg.UserToken = sck;
arg.Completed += new EventHandler<SocketAsyncEventArgs>(arg_Completed);
sck.ConnectAsync(arg);
void arg_Completed(object sender, SocketAsyncEventArgs e)
{
label1.Content = "Durum!";
if (e.LastOperation开发者_Python百科 == SocketAsyncOperation.Connect)
{
label1.Content = "Bağlandı!";
}
}
Have you considered that ConnectAsync
may not be completing asynchronously. Have a read of its documentation here.
You should be testing the returned boolean value from ConnectAsync
, if its true
then the completed event will fire, if not then the operation completed synchronously and ConnectAsync
will not fire. The fact that you are using the local 127.0.0.01 increases the likelyhood for a synchronous completion.
On a synchronous connection the args object you passed into the call will have been mutated accordingly.
精彩评论