问题描述
我开发一个SIP客户端。为此,我一定要听传入SIP Server消息端口5060。为此,我的东西编码。 (我也参加节目管理员权限)
I developing an SIP client. For this I must listen to port 5060 for incoming SIP Server messages. For this I coded something. (Also I take admin rights in program.)
WindowsPrincipal pricipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
bool hasAdministrativeRight = pricipal.IsInRole(WindowsBuiltInRole.Administrator);
if (hasAdministrativeRight == true)
{
TcpListener server;
Int32 port = 5060;
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
server = new TcpListener(localAddr, port);
server.Start();
Byte[] bytes = new Byte[256];
String data = null;
while (true)
{
Console.Write("Waiting for a connection... ");
TcpClient client = server.AcceptTcpClient();
Console.WriteLine("Connected!");
data = null;
NetworkStream stream = client.GetStream();
int i;
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
Console.WriteLine("Received: {0}", data);
data = data.ToUpper();
byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
stream.Write(msg, 0, msg.Length);
Console.WriteLine("Sent: {0}", data);
}
client.Close();
}
}
我得到SocketException:试图访问取得在某种程度上套接字由它的访问权限(本地错误代码:10013),禁止...
I get SocketException: "An attempt was made to access a socket in a way forbidden by its access permissions" (Native error code: 10013)...
你有这样的建议。
推荐答案
看来你正在运行两个应用程序,它们正试图
访问同一个插座上。
It seems that you were running two applications, and they are tryingto access the same socket.
什么:
WSAEACCES(10013)
- 翻译:权限被拒绝
-
说明:试图在
在被禁止的方式来访问套接字由其接入
的权限。例如,当一个广播地址
用于SENDTO但广播权限不使用
的setsockopt(SO_BROADCAST)设置发生此错误。
- Translation: Permission denied
Description: An attempt was made to access a socket in a way that is forbidden by its access permissions. For example, this error occurs when a broadcast address is used for sendto but the broadcast permission is not set by using setsockopt(SO_BROADCAST).
的另一个可能原因的WSAEACCES
错误是,当绑定(Wsapiref_6vzm.asp)函数被调用(在
的Microsoft Windows NT 4。 0的Service Pack 4 [SP4]或更高版本),另一个
程序,服务或内核模式驱动程序绑定到同一个地址
独家访问。这种独占访问是$ B $的新特征B的Windows NT 4.0 SP4和更高版本,它是通过使用
SO_EXCLUSIVEADDRUSE选项实现。
Another possible reason for the WSAEACCES error is that when the bind (Wsapiref_6vzm.asp) function is called (in Microsoft Windows NT 4 .0 Service Pack 4 [SP4] or later), another program, service, or kernel mode driver is bound to the same address with exclusive access. Such exclusive access is a new feature of Windows NT 4.0 SP4 and later, and it is implemented by using the SO_EXCLUSIVEADDRUSE option.
这篇关于监听端口5060的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!