UDP绑定错误10048 WSAEADDRINUSE [英] UDP bind error 10048 WSAEADDRINUSE

查看:438
本文介绍了UDP绑定错误10048 WSAEADDRINUSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我们遇到了一个奇怪的问题。


在我们的WEC7系统(imx6处理器)上有一个类似的线程这个:


  while(true){

    ServerSocket = socket(AF_INET,SOCK_DGRAM,0);

    address.sin_family = AF_INET;

    address.sin_addr.s_addr = htonl(INADDR_ANY);

    address.sin_port = htons(SETIP_PORT);


    bind(ServerSocket,(struct sockaddr *)& address,len); 


    setsockopt(ServerSocket,SOL_SOCKET,SO_BROADCAST,(char *)& allowed,sizeof(允许));

     recvfrom(ServerSocket,(char *)buffer,sizeof( buffer),0,(struct sockaddr *)& address_from,& len);


    sendto(ServerSocket,antwort,strlen(antwort),0,(sockaddr *)& sa,sizeof(sa));


    closesocket(ServerSocket);


}


这一直适用于我们的compony网络。从下午5点开始(当大多数人回家时) 在绑定我们得到约5分钟后错误10048 WSAEADDRINUSE。在我们ping设备之前,这种错误情况一直存在。然后它可以用于另一个
几分钟。


我们在WinCE5系统(XScale处理器)上运行相同的源代码多年来在同一环境中没有问题。


任何想法?






解决方案

我认为你也在骑行套接字快速(创造,使用,破坏)。尝试在循环输入之前创建并绑定服务器套接字一次,然后在循环退出之后关闭它一次。是的,你必须弄清楚何时退出循环,但你现在遇到同样的问题
但是你无缘无故地重复创建套接字套接字。我想你正在填写一个套接字列表,因为你正在争夺一些由closesocket()触发的垃圾收集线程。所有需要的是在
之前执行bind()的一次垃圾收集线程完成销毁旧套接字以生成此错误。


为什么只在下午5点,我不知道,但也许这是你申请的使用模式。


Paul T. / p>


hello,

we have encountered a strange problem.

On our WEC7 systems (imx6 processor) there is a thread like this:

 while (true) {
    ServerSocket = socket(AF_INET,SOCK_DGRAM,0);
    address.sin_family = AF_INET;
    address.sin_addr.s_addr = htonl(INADDR_ANY);
    address.sin_port = htons(SETIP_PORT);

    bind(ServerSocket,(struct sockaddr*)&address, len); 

    setsockopt(ServerSocket,SOL_SOCKET,SO_BROADCAST,(char*)&allowed,sizeof(allowed));
    recvfrom(ServerSocket,(char*)buffer,sizeof(buffer),0,(struct sockaddr*)&address_from,&len);

    sendto(ServerSocket,antwort,strlen(antwort),0,(sockaddr*)&sa,sizeof(sa));

    closesocket(ServerSocket);

}

This works well in our compony's network all the day. Starting at 5 p.m. (when most people go home)  at bind we get about after 5 minutes an error 10048 WSAEADDRINUSE. This error situation stays until we ping the devices. Then it works ok for another few minutes.

We have the same source code running on our WinCE5 systems (XScale processor) for years without problems in the same environment.

Any ideas ?

解决方案

I think you're cycling the sockets too fast (create, use, destroy). Try creating and binding the server socket once, before loop entry, and closing it once, after loop exit. Yes, you'll have to figure out when to exit the loop, but you have the same problem now but you're repeatedly creating socket after socket for no reason. I think you're filling up a list of sockets because you're racing against some garbage collection thread triggered by closesocket(). All it takes is one time where bind() executes before the garbage collection thread completes destroying the old sockets to generate this error.

Why only at 5pm, I have no idea, but maybe it's the usage pattern of your application.

Paul T.


这篇关于UDP绑定错误10048 WSAEADDRINUSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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