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

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

问题描述

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

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

为什么会出现这个错误?

Why does this error occur?

推荐答案

该错误通常意味着您尝试打开的端口已被另一个应用程序使用.尝试使用 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 地址(我假设它是 localhost)

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

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

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