Addresses that are already in use.
Normally, each socket address (protocol/IP address/port) is allowed to be used only once.
This error occurs if the application tries to bind a socket to an IP address/port that is already in use for an existing socket, or a socket that is not properly closed, or is still in the process of being closed.
For server applications that need to bind multiple sockets to the same port number, such as when a client process is taskkill and starts again, consider using setsockopt (SO_REUSEADDR).
Client applications usually do not need to call bind-connect to automatically select an unused port. When calling bind with a wildcard address (including ADDR_ANY), the WSAEADDRINUSE error may be delayed until a specific address is committed. This may occur later when another function is called, 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
Reproduced in: https://www.cnblogs.com/liujx2019/p/10811330.html
Read More:
- What should be paid attention to in socket programming — bind socket error: address already in use
- Creating Server TCP listening socket 127.0.0.1:6379: bind: No error。。。 Solutions to problems encountered in startup
- Creating Server TCP listening socket 127.0.0.1:6379: bind: No error
- Windows redis startup error reported: Creating Server TCP listening socket 127.0.0.1:6379: bind: No error
- The server just without updating PID file and can’t connect to local MySQL server through socket are solved
- Mongodb uses Mongo to report error: could’t connect to server 127.0.0.1:27017, connection attempt failed: socket
- Failed to connect to Mir:Failed to connect to server socket:No such file or directory
- nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
- [resolved] exception java.net.ConnectException : Error opening socket to server Connection timed out.
- It can’t connect to local MySQL server through socket ‘/ tmp/ mysql.sock ‘(2) “;
- filezilla Failed to create listen socket on port 21 for IPv4 solution
- [PHP]stream_socket_client(): Failed to enable crypto
- To the brothers who encountered simple bind failed 192.168.1.×××: 636
- Failed to bind properties under ‘‘ to com.zaxxer.hikari.HikariDataSource:
- Centos Failed to Modify the port of SSH: error: Bind to port 27615 on 0.0.0.0 failed: Permission denied.
- Elasticsearch startup process error: org.elasticsearch.transport .BindTransportException: Failed to bind to [9300-9400
- Server Tomcat v8.0 Server at localhost failed to start.
- Android: How to Solve Execution failed for task ‘:app:compileDebugJavaWithJavac‘. > javax/xml/bind/JAXBException
- Error: transport error 202: bind failed: address already in use
- Server Tomcat v7.0 server at localhost failed to start