WorkerRole在System.dll中抛出'System.Net.Sockets.SocketException' [英] WorkerRole throws 'System.Net.Sockets.SocketException' in System.dll

查看:50
本文介绍了WorkerRole在System.dll中抛出'System.Net.Sockets.SocketException'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用套接字将文件从Web角色移动到辅助角色,然后我将实体从辅助角色返回到Web角色,但是当工作进程在Worker中工作时套接字抛出了一个带有System.Net.Sockets.SocketException的AggregateException角色。记录: 

I move a file from Web Role to Worker Role using a socket, then I return entity from Worker Role to Web Role, but socket throws an AggregateException with System.Net.Sockets.SocketException when process work in Worker Role. Log: 

推荐答案

错误消息是"每个套接字地址只有一次使用"。这是通过调用Bind触发的。因此,您尝试将套接字绑定到已绑定的地址/端口。这是不允许的。您的服务器将绑定到它想要在启动时监听的地址/端口
。除非您更改地址/端口,否则它不会再次绑定。要监听连接,您将使用Accept方法。每次客户端连接时,都会为它们返回一个套接字。然后,您可以在辅助
线程上处理它,而主线程再次调用Accept以侦听下一个连接。

The error message is "Only one usage of each socket address". That is being triggered by a call to Bind. So you're attempting to bind a socket to an address/port that has already been bound. That is not allowed. Your server will Bind to the address/port it wants to listen on when it starts. It will not bind again unless you change the address/port. To listen for connections you'll be using the Accept method(s). Each time a client connects you get back a socket for them. You can then handle that on a secondary thread while your main thread calls Accept again to listen for the next connection.


TcpListener
有一个完整的示例,了解如何绑定到地址/端口并侦听连接。除非您需要低级套接字访问,否则这可能是要使用的类型。如果您确实需要较低级别的套接字访问权限,请参阅文档
以获取
套接字
,它还有一个如何绑定到端口并监听的完整示例。

The MSDN documentation for TcpListener has a complete example of how to bind to an address/port and listen for connections. Unless you need low-level socket access then this is probably the type to use. If you really need the lower-level socket access then refer to the documentation for Socket that also has a complete example of how to bind to the port and listen.


这篇关于WorkerRole在System.dll中抛出'System.Net.Sockets.SocketException'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆