绑定失败:地址已在使用中 [英] Bind failed: Address already in use

查看:279
本文介绍了绑定失败:地址已在使用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将套接字绑定到以下端口:

I am attempting to bind a socket to a port below:

if( bind(socket_desc,(struct sockaddr *) &server, sizeof(server)) < 0)
{
    perror("bind failed. Error");
    return 1;
}
puts("bind done");

但是它给出了:

$ ./serve   
Socket created    
bind failed. Error: Address already in use

为什么会出现此错误?

推荐答案

该错误通常表示您尝试打开的端口已被另一个应用程序使用.尝试使用netstat查看哪些端口已打开,然后使用可用端口.

The error usually means that the port you are trying to open is being already used by another application. Try using netstat to see which ports are open and then use an available port.

还要检查您是否绑定到正确的IP地址(我假设它是本地主机)

Also check if you are binding to the right ip address (I am assuming it would be localhost)

这篇关于绑定失败:地址已在使用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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