SilverLight 套接字问题
我正在尝试编写一个 silverlight 应用程序,套接字可以连接到 127.0.0.1:4505 但 arg.completed 事件不起作用
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 == SocketAsyncOperation.Connect)
{
label1.Content = "Bağlandı!";
}
}
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 == SocketAsyncOperation.Connect)
{
label1.Content = "Bağlandı!";
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过
ConnectAsync
可能无法异步完成。 此处阅读其文档。您应该测试从
ConnectAsync
返回的布尔值,如果为true
,则完成的事件将触发,如果不是,则操作同步完成,并且ConnectAsync
> 不会着火。您使用本地 127.0.0.01 的事实增加了同步完成的可能性。在同步连接上,您传递到调用中的 args 对象将相应地发生变化。
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 itstrue
then the completed event will fire, if not then the operation completed synchronously andConnectAsync
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.