Socket WSAG-Error: 10048
-
Hey,
mein Programm läuft zwar vollständig, doch wird ein Socket nicht gebunde.
rc=bind(acceptSocket,(SOCKADDR*)&addr,sizeof(SOCKADDR_IN)); if(rc==SOCKET_ERROR) { printf("Error, bind() failed: %d\n",WSAGetLastError()); return 1; }Wie kann ich soetwas verhindern?
Zu dem Fehlercode fand ich:/* WSAEADDRINUSE (10048) 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, 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. */
-
Der Fehlercode ist so nicht übersichtlich. Hier nochmals:
WSAEADDRINUSE (10048)
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, 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.
-
Hallo,
wie dieser Fehler verhindert werden kann ist nicht "so einfach" zu sagen,
nachfolgend ist einmal aufgeführt wie ich diese Bereiche immer ausführe:int flag_bind; SOCKET my_socket; struct sockaddr_in my_address; struct servent *service_info; service_info = getservbyname( "socket", "tcp" ); my_address.sin_family = AF_INET; my_address.sin_port = service_info->port; my_address.sin_addr.s_addr = INADDR_ANY; flag_bind = bind( my_socket, (struct sockaddr *)&my_address, sizeof(my_address) );... und immer daran denken das Sockets nicht nur geöffnet sondern auch
geschlossen werden müssen, vielleicht hilft das Vorstehende etwas.mfG ZZR-1100