Bind socket error 10048 astroneer

Bind fails with error 98 (or error 10048) A common socket programming error I hear about is error 98 (EADDRINUSE) or 10048 (WSAEADDRINUSE) from bind() . The Setup Maybe you are programming a server in C or C++. Your socket code might use a setup like this: If your call to bind fails, the […]

Содержание

  1. Bind fails with error 98 (or error 10048)
  2. The Setup
  3. Getting the Error Message
  4. What causes «Address already in use error»
  5. 1. Another program is using that port
  6. 2. Your program is already running
  7. 3. TCP Linger / TIME-WAIT
  8. Summary
  9. server: bind failed with error: 10048 #2
  10. Comments
  11. Bind failed with error code 10048
  12. bind failed with: 10048
  13. Guest
  14. Guest
  15. Guest

Bind fails with error 98 (or error 10048)

A common socket programming error I hear about is error 98 (EADDRINUSE) or 10048 (WSAEADDRINUSE) from bind() .

The Setup

Maybe you are programming a server in C or C++. Your socket code might use a setup like this:

If your call to bind fails, the first thing to do is check the error code. The error is stored in errno on Linux, but on Windows you will need to call WSAGetLastError() .

If the error returned by bind() is 98 (Linux) or 10048 (Windows), then it means the local port you are trying to bind to is already in use.

Getting the Error Message

By the way, you can also get the error message in text form.

On Linux it is just a call to strerror() . For error 98, that will return something such as «Address already in use».

Getting the error text on Windows is a bit trickier. There are instructions on getting the Windows error text here. The error message on Windows may be similar to «Only one usage of each socket address (protocol/address/port) is normally permitted.»

In any case, now that you know the what the error is, how do you fix it?

What causes «Address already in use error»

Basically, only one program can listen on a given protocol/address/port tuple at any given time. If more than one program were permitted to listen, then the operating system wouldn’t know which program to send incoming connections to.

When I hear about this error from readers, there is usually one of three causes.

1. Another program is using that port

The most obvious cause for the error is that another program is using the port you want to listen on. In this case, you can change the port your program listens on, or you can close the other program that is using that port.

On Linux, you can see which other programs are listening for connections using the netstat -ntlp command. The ntlp stands for «numeric tcp listen programs». In order words, we are asking netstat to show port numbers (numeric), to only show TCP sockets, to only show sockets in the listening state, and to show which programs are using the sockets.

The following screenshot shows using the netstat command on Linux to find which program is tying up port 8080.

As you can see above, the program tying up port 8080 is «server1» with a PID of 96939. Knowing the PID, you can easily kill the program if you like. Just please be sure you know what the program is and whether you really need it or not before you go around terminating things willy-nilly.

Windows also has a netstat command, but the usage is different. On Windows you can show all listening sockets with the command netstat -nao -p TCP | findstr LISTEN . Window’s netstat command doesn’t have an easy way to filter only listening sockets, so the findstr program comes in handy. In any case, running that command will list each listening TCP socket and show the owner program’s PID for each socket.

The following screenshot shows the usage of netstat on Windows to see which program is using port 8080:

As shown in the above screenshot, netstat lists each program’s listening address and PID. You can get more info on a PID with the tasklist command. For example, running tasklist | findstr 50396 would get us the program name for PID 50396 — the process we identified as using port 8080. For example:

The above screenshot shows that the program «server1.exe» has the PID of 50396, and therefore is the program using port 8080.

2. Your program is already running

This is more common than you think. Is your program already running? If it is, then of course the port is already in use!

This also isn’t always as easy to determine as you might like. In the server world, it’s very common for programs to run in the background or as daemons. In any case, if you get a bind() error or address already in use error, be sure to check that your program isn’t already running.

3. TCP Linger / TIME-WAIT

I’ve saved the most complicated scenario for last. Suppose your server program is running, and then you terminate it (or it crashes). When you restart it, you get the address in use error (EADDRINUSE or WSAEADDRINUSE). However, if you wait a couple minutes, you are able to start your program without error. What is going on here?

I won’t go into too much depth here (read my book for that), but basically when a socket is closed it can go into a TIME-WAIT state on the end that initiated the close. This isn’t a problem for a client program, since it doesn’t use bind() anyway (typically). However, this TIME-WAIT state can be a problem for server applications. It means the operating system is still keeping track of the closed socket, even after your entire program is closed. This is enough to cause the «Address already in use» error if you restart your program.

Now, there is an easy way to prevent this error on Linux. You can use the SO_REUSEADDR socket option before calling bind() . It looks like this:

This option will allow bind() to succeed even if a few TIME-WAIT connections are still around. There is very little downside to using the SO_REUSEADDR on Linux, so I suggest most server applications use it in that environment.

There is a major drawback to using this option on Windows. When using SO_REUSEADDR on Windows, the OS will simply allow multiple programs to bind to the same port. When an incoming connection is routed, it will only go to one program. This doesn’t mean you shouldn’t use SO_REUSEADDR on Windows, but you should certainly be aware of this behavior.

In any case, check out Chapter 13 of my book for more information.

Summary

If bind() causes error 98 (EADDRINUSE) or 10048 (WSAEADDRINUSE), it means you are trying to bind to a local port that is already in use. This is usually caused by one of three reasons:

  1. Another program is already using that port.
  2. Your program is already running and you’ve attempted to start it a second time.
  3. Your program was running recently and some connections are still lingering around in the half-dead TIME-WAIT state.

Cause 1 can be fixed by terminating the program using your port, or having your program use a different port.

Cause 2 can be fixed by only running one instance of your program at a time.

Cause 3 can be fixed by waiting a few minutes or by using the SO_REUSEADDR socket option on Linux. The SO_REUSEADDR option has the drawback on Windows that it will allow multiple programs to listen on the same port, but only one will actually receive connections.

I hope you found this article helpful. I’d love to hear any feedback you might have. Don’t hesitate to get in touch.

If you found this information helpful, you might be interested in my book.

Источник

server: bind failed with error: 10048 #2

I get the error server: bind failed with error: 10048 (port for remote management is busy, use different -mport value), next attempt in 20sec.

I am using windows and configured it as you said.

The text was updated successfully, but these errors were encountered:

Did you get the error on the no-fee-proxy window ?
It seems the port is already taken by the remote management engine.
Can you change the proxy port ? or change the claymore’s remote port (with -mport argument)

Yes, the error was in the proxy window. I can try and change one, and then the other and let you know.

This is just an issue on one of my rigs. The other rigs get different issues.

There are some weird connection issues with my other boxes as well. Most of the time they revert to the epools.txt. I can tell because I set a different name in the epools.txt so I can see in the pool display if they failed over.

They everyone one of my boxes fails over at least once an hour.

Are you using ethos by chance?

No, this is all on Windows.

I would be glad to help trouble shoot all of the issues I am experiencing. This is such a great project and I would like to help work the kinks out.

What can I do to assist?

I added you as a contributor, feel free to make changes as you see fit. I have some time to debug this tomorrow, also feel free to dm me in a gitter or something.

Источник

Bind failed with error code 10048

Сообщения: 1545
Благодарности: 48

Petya V4sechkin, в общем проблема оказалась в безобидном VNC-сервере. Он работает как служба.

Не понимаю, чем мог помешать VNC-сервер? Он занимает конкретные порты 5800 и 5900. И все.

А причем тут вышеуказанный порт 10048 тогда?

Каждый раз тушить VCN как-то нехорошо.

Сообщения: 52604
Благодарности: 15253

Конфигурация компьютера
Материнская плата: ASUS P8Z77-V LE PLUS
HDD: Samsung SSD 850 PRO 256 Гб, WD Green WD20EZRX 2 Тб
Звук: Realtek ALC889 HD Audio
CD/DVD: ASUS DRW-24B5ST
ОС: Windows 10 Pro x64

А причем тут вышеуказанный порт 10048 тогда?

Это не порт, а код ошибки Winsock.

Он занимает конкретные порты 5800 и 5900

Это сообщение посчитали полезным следующие участники:

Порты можно изменить в настройках. »

Изменил в на сервере VNC порт 5800 на 5801 — теперь проблемная программа работает.
Но что интересно, то запущенный процесс от этой программы (TransData.exe) не занимает ни один порт, о чем свидетельствует netstat -aon. Также юзал tcpview — там процесс TransData.exe не отображается.

Т.е. может быть такое, что при запуске программа смотрит наличия доступа на порт 5800 и если его нет, то не стартует. Иначе же запускается, но порт не занимает.

?

Сообщения: 52604
Благодарности: 15253

Конфигурация компьютера
Материнская плата: ASUS P8Z77-V LE PLUS
HDD: Samsung SSD 850 PRO 256 Гб, WD Green WD20EZRX 2 Тб
Звук: Realtek ALC889 HD Audio
CD/DVD: ASUS DRW-24B5ST
ОС: Windows 10 Pro x64

не занимает ни один порт, о чем свидетельствует netstat -aon. Также юзал tcpview

Это сообщение посчитали полезным следующие участники:

Guest

Guest

Archived from groups: microsoft.public.windowsxp.general (More info?)

When attempting to run the configuration utility (from CD or HD) for a
wireless access point, I get the following error message: «bind failed with:
10048″. The utility program appears on the Windows taskbar, but a window does
not appear on the desktop from which to work with the program. I am running
XP SP2 on an Acer Travelmate 2200. Any guidance in getting this resolve would
appreciated.

Distinguished

Archived from groups: microsoft.public.windowsxp.general (More info?)

> When attempting to run the configuration utility (from CD or HD) for a
> wireless access point, I get the following error message: «bind failed with:
> 10048″. The utility program appears on the Windows taskbar, but a window does
> not appear on the desktop from which to work with the program. I am running
> XP SP2 on an Acer Travelmate 2200. Any guidance in getting this resolve would
> appreciated.


Rock
MS MVP Windows — Shell/User

Guest

Guest

Archived from groups: microsoft.public.windowsxp.general (More info?)

> When attempting to run the configuration utility (from CD or HD) for a
> wireless access point, I get the following error message: «bind failed
> with: 10048″.

Contact the manufacturer’s technical support. That’s always the first
approach. Make also sure that the AP is connected prior to running that
utility.

Guest

Guest

Archived from groups: microsoft.public.windowsxp.general (More info?)

Thanks for the reply. I did not state it in the original post, but I had
contacted OEM support and downloaded the latest version of the utility with
the same result. Also, AP has been connected each time that I have tried to
run the utility. I have also tried it with the AP disconnected when started
the program, just to change up the dynamics, to no avail. The computer tech
support was of no help. I am still banging my head against the wall on this
one.

«Detlev Dreyer» wrote:

> Roy W. wrote:
>
> > When attempting to run the configuration utility (from CD or HD) for a
> > wireless access point, I get the following error message: «bind failed
> > with: 10048″.
>
> Contact the manufacturer’s technical support. That’s always the first
> approach. Make also sure that the AP is connected prior to running that
> utility.
>
> —
> d-d
>

Источник

Adblock
detector

bind failed with: 10048

I started with the simple server tutorial on the msdn website in order to learn how to use sockets in client and server applications.

Once I was done following thet tutorial, I started adapting the client and server code into multithreaded proggrams in order to make a tchat client and server. Everything was going very well until I ran into WSA error 10048. I tried using different ports for each socket but it still did not solve the error.

Here is my server code :

#undef UNICODE

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <thread>
#include <vector>

// Need to link with Ws2_32.lib
#pragma comment (lib, "Ws2_32.lib")
// #pragma comment (lib, "Mswsock.lib")

//Global values
//I put them as global values in order to get the server up and running.
//I will try to pass them as params later on
int iResult;
struct addrinfo *result = NULL;
struct addrinfo hints;
int numClients = 0;
SOCKET ClientSocket[5];
std::thread** sendReceiveThread = new std::thread*[5];

//Prototypes
int listen(SOCKET ListenSocket);
int accept(SOCKET ListenSocket);
int sendReceive();
int shutdownFunction(SOCKET ClientSocket);

#define DEFAULT_BUFLEN 512
#define DEFAULT_PORT1 "1016"
#define DEFAULT_PORT2 "1017"
#define DEFAULT_PORT3 "1018"
#define DEFAULT_PORT4 "1019"
#define DEFAULT_PORT5 "1020"

int main()
{
    std::cout << 1 << std::endl;
    WSADATA wsaData;

    SOCKET ListenSocket = INVALID_SOCKET;


    // Initialize Winsock
    std::cout << 2 << std::endl;
    iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (iResult != 0) {
        std::cout << 3 << std::endl;
        printf("WSAStartup failed with error: %dn", iResult);
        return 1;
    }

    ZeroMemory(&hints, sizeof(hints));
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = IPPROTO_TCP;
    hints.ai_flags = AI_PASSIVE;

    std::thread ListenThread{ [ListenSocket](){listen(ListenSocket); } };
    ListenThread.join();

    return 0;
}

int listen(SOCKET ListenSocket)
{
    int numPort = 1;
    std::vector<std::thread*> thread_vec;
    while (true)
    {
        if (numPort == 1)
        {
            // Resolve the server address and port
            std::cout << 4 << std::endl;
            iResult = getaddrinfo(NULL, DEFAULT_PORT1, &hints, &result);
            numPort++;
            if (iResult != 0) {
                std::cout << 5 << std::endl;
                printf("getaddrinfo failed with error: %dn", iResult);
                WSACleanup();
                break;
            }
        }

        else if (numPort == 2)
        {
            // Resolve the server address and port
            std::cout << 4 << std::endl;
            iResult = getaddrinfo(NULL, DEFAULT_PORT2, &hints, &result);
            numPort++;
            if (iResult != 0) {
                std::cout << 5 << std::endl;
                printf("getaddrinfo failed with error: %dn", iResult);
                WSACleanup();
                break;
            }
        }

        else if (numPort == 3)
        {
            // Resolve the server address and port
            std::cout << 4 << std::endl;
            iResult = getaddrinfo(NULL, DEFAULT_PORT3, &hints, &result);
            numPort++;
            if (iResult != 0) {
                std::cout << 5 << std::endl;
                printf("getaddrinfo failed with error: %dn", iResult);
                WSACleanup();
                break;
            }
        }

        else if (numPort == 4)
        {
            // Resolve the server address and port
            std::cout << 4 << std::endl;
            iResult = getaddrinfo(NULL, DEFAULT_PORT4, &hints, &result);
            numPort++;
            if (iResult != 0) {
                std::cout << 5 << std::endl;
                printf("getaddrinfo failed with error: %dn", iResult);
                WSACleanup();
                break;
            }
        }

        else if (numPort == 5)
        {
            // Resolve the server address and port
            std::cout << 4 << std::endl;
            iResult = getaddrinfo(NULL, DEFAULT_PORT5, &hints, &result);
            numPort++;
            if (iResult != 0) {
                std::cout << 5 << std::endl;
                printf("getaddrinfo failed with error: %dn", iResult);
                WSACleanup();
                break;
            }
        }

        // Create a SOCKET for connecting to server
        std::cout << 6 << std::endl;
        ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
        if (ListenSocket == INVALID_SOCKET) {
            std::cout << 7 << std::endl;
            printf("socket failed with error: %ldn", WSAGetLastError());
            freeaddrinfo(result);
            WSACleanup();
            break;
        }

        // Setup the TCP listening socket
        std::cout << 8 << std::endl;
        iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen);
        if (iResult == SOCKET_ERROR) {
            std::cout << 9 << std::endl;
            printf("bind failed with error: %dn", WSAGetLastError());
            freeaddrinfo(result);
            closesocket(ListenSocket);
            WSACleanup();
            break;
        }

        freeaddrinfo(result);

        std::cout << 10 << std::endl;
        iResult = listen(ListenSocket, SOMAXCONN);
        if (iResult == SOCKET_ERROR) {
            std::cout << 11 << std::endl;
            printf("listen failed with error: %dn", WSAGetLastError());
            closesocket(ListenSocket);
            WSACleanup();
            break;
        }


        static std::thread AcceptThread{ [ListenSocket](){accept(ListenSocket); } };
        thread_vec.push_back(&AcceptThread);
    }
    for (auto it : thread_vec) it->join();
    return 0;
}

int accept(SOCKET ListenSocket)
{
    numClients++;
    const int currentNumClients = numClients;
    for (int i = 0; i <= 5; i++)
    {
        ClientSocket[i] = INVALID_SOCKET;
    }

    // Accept a client socket
    std::cout << 12 << std::endl;

    std::cout << 13 << std::endl;

    ClientSocket[currentNumClients] = accept(ListenSocket, NULL, NULL);
    if (ClientSocket[currentNumClients] == INVALID_SOCKET)
    {
        printf("accept failed with error: %dn", WSAGetLastError());
        closesocket(ListenSocket);
        WSACleanup();
        return 1;
    }

    sendReceiveThread[currentNumClients] = new std::thread([](){sendReceive(); });
    (*sendReceiveThread[currentNumClients]).join();
    delete sendReceiveThread[currentNumClients];

    return 0;
}

int sendReceive()
{
    int currentNumClients = numClients;
    int iSendResult;
    char recvbuf[DEFAULT_BUFLEN];
    int recvbuflen = DEFAULT_BUFLEN;

    // Receive until the peer shuts down the connection
    while(true)
    {
        std::cout << 14 << std::endl;
        iResult = recv(ClientSocket[currentNumClients], recvbuf, recvbuflen, 0);
        std::cout << iResult << std::endl;
        if (iResult > 0) {
            std::cout << 15 << std::endl;
            printf("Bytes received: %dn", iResult);

            // Echo the buffer back to the clients
            std::cout << 16 << std::endl;
            for (int i = 1; i <= numClients; i++)
            {
                iSendResult = send(ClientSocket[currentNumClients], recvbuf, iResult, 0);
                if (iSendResult == SOCKET_ERROR) {
                    std::cout << 17 << std::endl;
                    printf("send failed with error: %dn", WSAGetLastError());
                    closesocket(ClientSocket[currentNumClients]);
                    WSACleanup();
                    return 1;
                }
                printf("Bytes sent: %dn", iSendResult);
            }
        }
        else if (iResult == 0) {
            std::cout << 18 << std::endl;
            printf("Connection closing...n");
            break;
        }
        else {
            std::cout << 19 << std::endl;
            printf("recv failed with error: %dn", WSAGetLastError());
            std::cout << "On client #" << currentNumClients << std::endl;
            break;
        }

    }

    iResult = shutdownFunction(ClientSocket[currentNumClients]);

    std::cout << 22 << std::endl;
    // cleanup
    closesocket(ClientSocket[currentNumClients]);
    WSACleanup();

    return 0;
}

int shutdownFunction(SOCKET ClientSocket)
{
    std::cout << 20 << std::endl;
    iResult = shutdown(ClientSocket, SD_SEND);
    if (iResult == SOCKET_ERROR) {
        std::cout << 21 << std::endl;
        printf("shutdown failed with error: %dn", WSAGetLastError());
        closesocket(ClientSocket);
        WSACleanup();
        return 1;
    }

    return 0;
}

You might notice the different couts, those are just couts to know how the proggram behaves.

RRS feed

  • Remove From My Forums
  • Question

  • Hello,
      My application a simple MDI application.Take data in serial port and send it to another computer using tcp/ip .
    In the first iterartion every thing is fine.Both server and client systems works well.
    Then if the server is turned of off(disconnect using socket.close() method) and then client is also closed .
    without closing the application if i start open the socket and execute socket.bind() method , the exception 10048

    thanks in advance.

    cheers,
    watashi

All replies

  • It means that yProxy is unable to bind to the Local (Proxy) Port that you have configured. That port is probably already in use.

  • Hello,
     Thnks for u  r reply.but as i hv stated the same application was using that ip and port and are closed using close() method.And then when try to open the same ip and port which was closed then i m getting the above error.

  • The problem is that binding and unbinding to endpoints is a costly operation for the Operating System.. And it takes a while before it is performed… If you want to speed up this process you’ll have to find a way to pass in the option SO_REUSEADDR (i can’t remember the .net equivalent right now) to notify the OS that the resource has to be cleaned up faster (and thus make it available faster)…

    serverSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.ReuseAddress, true);

    (Another interesting setting could be HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParametersTcpTimedWaitDelay)

  • thnks a lot
     But i didnt get that interesting setting « HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParametersTcpTimedWaitDelay)»

  • Basically a TCP connection is unique with the combination of (client ip, client socket, server ip, server socket).

    I can think of two issues in this case

      1. the previous connection with this combination is still alive in the system.(do a netstat -a). Most probably it will be in TIME_WAIT state.

      2. and you are again trying to make use of same combination in next request. 

    Thats the reason it gives that error.

    May be you can use SO_REUSEADDR or SO_EXCLUSIVEADDRUSE while trying to connect again.

    -Sushil

  1. 04-06-16


    #1

    [Solved] socketmanagerudp bind failed with error 10048

    I got this error. does anybody also have this same problem?


  2. [Solved] socketmanagerudp bind failed with error 10048


  3. 04-06-16


    #2

    Re: socketmanagerudp bind failed with error 10048

    bind errors are usually meaning that the port is already running if i am right/by another program or something.


  4. 05-06-16


    #3

    Re: socketmanagerudp bind failed with error 10048

    Quote Originally Posted by KarLi
    View Post

    bind errors are usually meaning that the port is already running if i am right/by another program or something.

    problem solved. thanks mate


  5. 07-06-16


    #4


    Member Death2015 is offline


    Re: socketmanagerudp bind failed with error 10048

    Quote Originally Posted by cambio28
    View Post

    problem solved. thanks mate

    What was the problem ?


  6. 07-06-16


    #5

    Re: socketmanagerudp bind failed with error 10048

    Quote Originally Posted by Death2015
    View Post

    What was the problem ?

    port was used somewhere by other program, u could read my post.


Понравилась статья? Поделить с друзьями:
  • Benvenuto classic bosch ошибки
  • Below is a rendering of the page up to the first error как исправить
  • Below is a rendering of the page up to the first error xml
  • Below is a rendering of the page up to the first error wordpress
  • Bind failed with error 10049