Address already in use.
Typically, only one usage of each socket address (protocol/IP address/port) is permitted.
This error occurs if an application attempts to bind a socket to an IP address/port that has already been used for an existing socket, or a socket that wasn’t closed properly, or one that is still in the process of closing.
For server applications that need to bind multiple sockets to the same port number, for example, the case where the client process is taskkilled and started again consider using setsockopt(SO_REUSEADDR).
Client applications usually need not call bind at all—connect chooses an unused port automatically. When bind is called with a wildcard address (involving ADDR_ANY), a WSAEADDRINUSE error could be delayed until the specific address is committed. This could happen with a call to another function later, including connect, listen, WSAConnect, or WSAJoinLeaf.
BOOL bOptVal = TRUE;
int bOptLen = sizeof(BOOL);
iResult = setsockopt(ListenSocket, SOL_SOCKET, SO_REUSEADDR, (char *)&bOptVal, bOptLen);
if (iResult == SOCKET_ERROR)
{
char m[500];
snprintf(m, 500, "%s %d: setsockopt failed, port %d failed with error: %d",
__func__, __LINE__, port_number, WSAGetLastError());
printf("%s\n", m);
freeaddrinfo(result);
closesocket(ListenSocket);
WSACleanup();
return -1;
}
https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-setsockopt
Similar Posts:
- [Solved] activemq Startup Error: Address already in use: JVM_Bind
- Programming udp sockets in python
- python 3.6 socket tcp Connect TypeError: a bytes-like object is required, not ‘str’
- Python Error: Socket TypeError: a bytes-like object is required, not ‘str’ [How to Solve]
- adb server version (31) doesn’t match this client (41); killing…
- [Solved] #Creating Server TCP listening socket *:6379: bind: Address already in use
- Solution of soap can not connect to host in
- How to Solve Error: [errno 99] cannot assign requested address error:
- [Solved] psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”?
- Error: Flask Address already in use [How to Solve]