绑定失败。错误:地址已在使用

绑定失败。错误:地址已在使用

问题描述:

我Socket编程很新,LINUX,C ..这是程序的Socket我绑定一部分

I am new in Socket programming,Linux ,C.. This is my Bind part of the Socket program

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

但它给

用户桌面:〜/ socket_programming $ ./server

插座创建

绑定失败。错误:地址已在使用

我不知道如何解决这个问题..请给我一个解决方案。

I don't know how to fix this problem.. Please give me a solution..

该错误通常意味着你试图打开的端口被已被另一个应用程序尝试使用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)