Socket error 10048 python

socket error 10048 python

0.0, 2345). Multiprocessing causes the module to try (retryorno) import into a new. This error means that you already have a service in the port 5005. Check this to see what it is. ashwinijdhav1991 (Ashwini Jadhav) January. I've been testing it a while and it seems to be a server side problem. When too many requests are done in a brief period of time, server refuses.

Related Videos

How To Fix Windows Sockets Initialization Failed Error On Windows 10/8/7

Socket error 10048 python -

A socket program recently written in python has run with an error:
socket.error: [Errno 10048] normally each socket address (protocol/network address/port) is allowed only once
After searching, it is found that this prompt appears when the port is in conflict. The possible reason is that after a Socket is created in the server program and a port is opened, the Socket is not closed at the end of the program. Therefore, this error prompt will appear next time the program is started.
1, at the end of the server program to close the Socket
2. Or change the port number
3. Restart the machine
Win7 system quickly check the port number and pid process number:
1. Press Win+R key, enter CMD, open the command line.
2. Enter netstat -aon

OS Error: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted #14

Hello @Miguel-g-c,
I also need a solution to fixed up the OSError: [WinError 10048].
I saved your code tobe the file main.py and tested by cmd "python main.py." However, I got the following result.


Ran 1 test in 4.080s

FAILED (errors=1)


The error hints are,

Traceback (most recent call last):
File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 158, in _new_conn
conn = connection.create_connection(
File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\connection.py", line 80, in create_connection
raise err
File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\connection.py", line 70, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 無法連線,因為目標電腦拒絕連線。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 597, in urlopen
httplib_response = self._make_request(conn, method, url,
File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1276, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1322, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1271, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1031, in _send_output
self.send(msg)
File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 969, in send
self.connect()
File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 181, in connect
conn = self._new_conn()
File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 167, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000001609DA22D40>: Failed to establish a new connection: [WinError 10061] 無法連線,因為目標電腦拒絕連線。

Python Server Client program error: "OSError: [WinError 10048]"

So I'm studying Python from the book Fundamentals of Python by Kenneth Lambert and I'm having trouble with an error from one of the programs in the book.

Here in chapter 10 talks about Clients and Servers. My professor asked us to key those programs in Python to see how they work. The first programs worked perfectly, but in a program I'm getting an error which seems to be a Windows error instead of a Python one.

This is the program in page 339:

When I run this program, it displays the "Waiting for connection" message in the Shell. However, when I try to connect to the program using the Command Prompt, it displays the following error:

We haven't studied this in class a lot. So I'm just wondering why this happens and how to fix it.

Thanks!

asked May 11, 2014 at 17:54

user avatar
user3451338user3451338

8911 gold badge11 silver badge77 bronze badges

An example of Python socket programming: simulating various common winerror situations

Recently, I used Python Wrote a little tool for testing , Maybe it works like this :

This gadget works as a server , Request information from the client , Do something about it , Then return the message synchronously or asynchronously .

For this gadget , It mainly works as the server of the requested service . And in the development of this gadget , I often encounter things like Python Socket programming Or something like that .

I've met a lot , I find , Instead of meeting a WinError Error and search for the reason , Let's write a simple one based on TCP The server-side client communication program of , Come and take these by yourself WinError The wrong situation is simulated , such , We're going to treat these as well WinError Mistakes have a deeper understanding .

Do what you say , First, the simplest use of Python Socket The server-side client communication program realized by programming . then , We build on this code , All kinds of operations , To simulate the implementation of some common WinError error .

here , Go straight to the code :

1. Code

Server program

Client program

2. analysis

about Socket Programmatically , All languages are the same ,Python No exception . In this case :

The server side program is bound with a 9999 port , Then listen to the client socket The connection of . The two floors here while loop , The outer layer is used to traverse the connection requests of multiple clients , The inner layer is used to realize the interaction with the client to receive and send data .

The client program connects to the server port , And then you go into a loop , Used to send data to the server .

here , First run the server side program , Then run the client program , The client sends the message first , Server received , Then the server sends the message to the client , Client received , The client can continue to send messages to the server … until , Client input bye, Then jump out of the loop , Close the client's socket Connect , And that's the end of the process .

1

This is a very simple server-side client communication program , We can use this program to simulate all kinds of WinError error . Let's start next :)

[WinError 10061] Because the target computer actively refuses , Unable to connect

We just said , Run this program , You need to run the server program first , Then run the client program , This is because the server monitors first , Then the client will connect to .

that , If the server program is not started first , At this point, the client runs , What kind of mistakes will happen ?
2
Sum up :

Once the client starts , The server does not want to connect on the client side IP And port number , Then there will be Error of .

[WinError 10054] The remote host forced an existing connection to be closed

Let's run the server program first , Then run the client program , And then the client program will be forced to kill ( Don't let it shut down properly socket Connect ), What kind of mistakes will occur at this time ?

3
This mistake is easy to understand , Connected to socket The connection is forcibly interrupted by the other party ( abnormal close Dropped ), This error will appear .

Some netizens may feel that , Here is the client force kill , So what's wrong with killing the server ? ha-ha , You can try it yourself , The answer is no mistake :) why , You can think for yourself , Here's just a hint , A client only connects to one server , But a server , It is to connect zero one or more clients .

Sum up :

When the client connects to the server , The client program is forced to kill , At this point, the server will report an error

[WinError 10048] Usually every socket address ( agreement / network address / port ) Only one use is allowed

Let's modify the client code a little bit , Try not to let the client go connect Server side socket Connect , It is bind( It's like the server ), Revised as follows :

What's the problem ?

4
In fact, this is also very easy to understand , After all, the same port is monitored by two programs , There is bound to be a port occupancy problem .

Sum up :

A port has been occupied , And then another program wants to use it , There will be errors

[WinError 10038] An operation was attempted on a non socket

We're going to change the code this time , This time we modify the server-side code :

What we modified is server.py, The original close The function is put inside the loop , Lead to close Then I call once recv. Let's run the server program first , Then run the client program to see what happens :
1
We found that , On the server side, the program runs to recv When it comes to Error of , Actually, it's easy to understand , Because after all, you've put this socket The connection is closed , And then you want to use it to receive data .

To sum up :

When you shut down a socket Connect (close), And then use that socket Object receives data (recv), There will be an error

... To be continued , Keep updating

If in the follow-up work , There are other interesting error messages , I'll also come here to keep updating :)

Study Python Ben is a very happy thing , Happier than it is , That's using Python The process of .

Python The way , The road is long but not boring ~~~
To be Stronger:)

版权声明
本文为[I've been to places that span an hour]所创,转载请带上原文链接,感谢

error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

I am creating system tests on a Windows7 machine using python, in which I need to open various socket connections to other machines. I also have several virtual IPs added to the local machine.

These tests sometimes work, but when executed quickly after each other, I always run into the following error:

This problem has been posted a couple of time, but no answer seems to solve the problem on my computer. Here are some more specific information:

  • Each socket created in python has the following option set:

  • I also changed entries following the hints to avoiding ports exhaustion, which does not fix my problem. only shows about max. 30 ports in state 'ESTABLISHED' or 'TIME_WAIT' up to port number 10000.

  • As far as I can tell from the code, the connections are all closed. But even if they aren't, I need the connections to be closed or to be reused immediately.

How can I fix this problem to avoid this error?

Current code implementation:

Solved: Suggestions To Fix Error 10048 One Use Per Socket

If you only get error 10048 once using each socket error, this tutorial is for you.

Speed up your computer in minutes

  • Step 1: Download and install ASR Pro
  • Step 2: Open the program and click "Scan"
  • Step 3: Click "Repair" to start the repair process
  • Click here to get the software that will improve your computer's performance.

    If you see some kind of error: “Only one use of each socket address (protocol / network address / port) is active authorization” in the logs when fully connected, this will mean that you have all the available network connections of the coffee machine … By default, only about 4000 ports are available in the operating system, which are not reserved by the system. When a system connection is closed, it can enter the TIME_WAIT state for 240 seconds and cannot be reused until a certain wait state has passed.

    For example, if there are 16 connections per second for online connections for 4 minutes (16 * 4 * 60 = 3840), clients will quickly exhaust all ports after that. Now, if you already have HAS and MTA on the same computer, it will get sick much earlier, because besides them, almost everyone communicates with each other using 2 ports (one for receiving MTA and the other for HAS), MTA uses many ports for sending e-mail.

    1. One way is to increase the overall dynamic range of the port. The default maximum is 5000. You canDon’t set this skill to 65534. HKLMSystemCurrentControlSetServicesTcpipParametersMaxUserPort is just a key to use it.

    2. The second thing you and your family can do is after you connect to the TIME_WAIT Express, you will shorten the time it stays in this state. By default, it is only 4 minutes, but you can set it to 30 seconds.
      HKLMSystemCurrentControlSetServicesTcpipParametersTCPTimedWaitDelay is the button that should be used.

    I have two different Python packages on the same computer. One is using a Socket to connect another server to the servers of another computer on my system, the second is acting as a specific websocket server that other clients can access. The two scripts are just not related. When you start to run, the second run of the person is already the first. I get

    Etit says that you cannot have two different scripts on the same computer that only use sockets / websockets. This is right? Education?

    Requested Feb 17 at 4:49 pm.

    Isn’t That What You Are Looking For? Browse Through Many Tagged Questions With Python Sockets Websocket, Or Maybe Ask Your Own Question.

    Speed up your computer in minutes

    Are you tired of your computer running slowly? Is it riddled with viruses and malware? Fear not, my friend, for ASR Pro is here to save the day! This powerful tool is designed to diagnose and repair all manner of Windows issues, while also boosting performance, optimizing memory, and keeping your PC running like new. So don't wait any longer - download ASR Pro today!

  • Step 1: Download and install ASR Pro
  • Step 2: Open the program and click "Scan"
  • Step 3: Click "Repair" to start the repair process

  • They come up with two scripts that finally try to become a server on the same port.

    error message 10048 only one usage of each socket

    This is unacceptable because when your system receives a new connection on its port, how does it know who, in turn, is receiving the script for the new connection?

    If we have two servers, they must use different port numbers.

    responds on February 17 at 16:51

    error message 10048 only one usage of each socket

    48k 66 badges 4444 silver badges 7878 brown badges

    Click here to get the software that will improve your computer's performance.

    Messaggio Di Errore 10048 Solo Un Utilizzo Di Ogni Socket
    Fehlermeldung 10048 Nur Eine Verwendung Pro Socket
    Message D Erreur 10048 Une Seule Utilisation De Chaque Socket
    오류 메시지 10048 각 소켓의 한 번만 사용
    Mensaje De Error 10048 Solo Un Uso De Cada Enchufe
    Felmeddelande 10048 Endast En Anvandning Av Varje Socket
    Komunikat O Bledzie 10048 Tylko Jedno Uzycie Kazdego Gniazda
    Mensagem De Erro 10048 Apenas Um Uso De Cada Soquete
    Foutmelding 10048 Slechts Een Gebruik Van Elke Socket
    Soobshenie Ob Oshibke 10048 Tolko Odno Ispolzovanie Kazhdogo Soketa

     #address protocol network#apache#bind#blender#eel#errno 10048#github#oserror winerror 10048#prodigy#python#quixel#sql server#tcp#tcp ip#tcp port#tcpip parameters

    [WinError 10048] Only one usage of each socket address ... #3031

    The reason your code doesn't have that side effect is because the server is closing the connection first. That's because your code is performing a HTTP/0.9 style GET request, which requires the server to close the connection to signal the end of the response. That means that the server is almost certainly getting a socket in TIME_WAIT instead, which is much worse than you getting a socket in TIME_WAIT.

    To avoid getting sockets in TIME_WAIT, the best thing to do is to use a single Session object at as high a scope as you can and leave it open for the lifetime of your program. Requests will do its best to re-use the sockets as much as possible, which should prevent them lapsing into TIME_WAIT. But you cannot avoid TIME_WAIT if you want to be closing the sockets yourself: it is a critical part of the TCP state machine that exists for a very good reason.

    Shutdown does not prevent TIME_WAIT. I don't really know why you think it does.

    socket error 10048 python

    error 105 partition OS Error: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted #14

    Hello @Miguel-g-c,
    I also need a solution to fixed up the OSError: [WinError 10048].
    I saved your code tobe the file main.py and tested by cmd "python main.py." However, I socket error 10048 python the following result.


    Ran 1 test in 4.080s

    FAILED (errors=1)


    The error hints are,

    Traceback (most recent call last):
    File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 158, in _new_conn
    conn = connection.create_connection(
    File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\connection.py", line 80, in create_connection
    raise err
    File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\connection.py", line 70, in create_connection
    sock.connect(sa)
    ConnectionRefusedError: [WinError 10061] 無法連線,因為目標電腦拒絕連線。

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 597, in urlopen
    httplib_response = self._make_request(conn, method, url,
    File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
    File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1276, in request
    self._send_request(method, url, socket error 10048 python, body, headers, encode_chunked)
    File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1322, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
    File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1271, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
    File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1031, in _send_output
    self.send(msg)
    File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 969, in send
    self.connect()
    File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 181, in connect
    conn = self._new_conn()
    File "C:\Users\yvechang\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 167, in _new_conn
    raise NewConnectionError(
    urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000001609DA22D40>: Failed to establish a new connection: [WinError 10061] 無法連線,因為目標電腦拒絕連線。

    Solved: Suggestions To Fix Error 10048 One Use Per Socket

    If you only get error 10048 once using each socket error, this tutorial is for you.

    Speed up your computer in minutes

  • Step 1: Download and install ASR Pro
  • Step 2: Open the program and click "Scan"
  • Step 3: Click "Repair" to start the repair process
  • Click here to get the software that will improve your computer's performance.

    If you see some kind sound driver error directx/wdm error: “Only one use of each socket address (protocol / network address / port) is active authorization” in the logs when fully connected, this will mean that you have all the available network connections of the coffee machine … By default, only about 4000 ports are available in the operating system, which are not reserved by the system. When a system connection is closed, it can enter the TIME_WAIT state for 240 seconds and cannot be reused until a certain wait error address 0000h has passed.

    For example, if there are 16 connections per second for online connections for 4 minutes (16 * 4 * 60 = 3840), clients will quickly exhaust all ports after that. Now, if you already have HAS and MTA on the same computer, socket error 10048 python, it will get sick much earlier, because besides them, almost everyone communicates with each other using 2 ports (one for receiving MTA and the other for HAS), MTA uses many ports for sending e-mail.

    1. One way is to increase the overall dynamic range of the port. The default maximum is 5000. You canDon’t set this skill to 65534. HKLMSystemCurrentControlSetServicesTcpipParametersMaxUserPort is just a key to use it.

    2. The second thing you and your family can do is after you connect to the TIME_WAIT Express, socket error 10048 python, you will shorten the time it stays in this state. By default, it is only 4 minutes, but you can set it to 30 seconds.
      HKLMSystemCurrentControlSetServicesTcpipParametersTCPTimedWaitDelay is the button that should be used.

    I have two different Python packages on the same computer. One is using a Socket to connect another server to the servers of another computer on my system, the second is acting as a specific websocket server that other clients can access. The two scripts are just not related. When you start to run, the second run of the person is already the first. I get

    Etit says that you cannot have two different scripts on the same computer that only use sockets / websockets. This is right? Education?

    Requested Feb 17 at 4:49 pm.

    Isn’t That What You Are Looking For? Browse Through Many Tagged Questions With Youtube 500 internal server error Sockets Websocket, Or Maybe Ask Your Own Question.

    Speed up your computer in minutes

    Are you tired of your computer running slowly? Is it riddled with viruses and malware? Fear not, my friend, for ASR Pro is here to save the day! This powerful tool is designed to diagnose and repair all manner of Windows issues, while also boosting performance, optimizing memory, and keeping your PC running like new. So don't wait any longer - download ASR Pro today!

  • Step 1: Download and install ASR Pro
  • Step 2: Open the program and click "Scan"
  • Step 3: Click "Repair" to start the repair process

  • They come up with two scripts that finally try to become a server on the same port.

    error message 10048 only one usage of each socket

    This is unacceptable because when your system receives a new connection on its port, how does it know who, in turn, is receiving the script for the new connection?

    If we have two servers, they must use different port numbers.

    responds on February 17 at 16:51

    error message 10048 only one usage of each socket

    48k 66 badges 4444 silver badges socket error 10048 python 7878 brown badges

    Click here to get the software that will improve your computer's performance.

    Messaggio Di Errore 10048 Solo Un Utilizzo Di Ogni Socket
    Fehlermeldung 10048 Nur Eine Verwendung Pro Socket
    Message D Erreur 10048 Une Seule Utilisation De Chaque Socket
    오류 메시지 10048 각 소켓의 한 번만 사용
    Mensaje De Error 10048 Solo Un Uso De Cada Enchufe
    Felmeddelande 10048 Endast En Anvandning Av Varje Socket
    Komunikat O Bledzie 10048 Tylko Jedno Uzycie Kazdego Gniazda
    Mensagem De Erro 10048 Apenas Um Uso De Cada Soquete
    Foutmelding 10048 Slechts Een Gebruik Van Elke Socket
    Soobshenie Ob Oshibke 10048 Tolko Odno Ispolzovanie Kazhdogo Soketa

     #address protocol network#apache#bind#blender#eel#errno 10048#github#oserror winerror 10048#prodigy#python#quixel#sql server#tcp#tcp ip#tcp port#tcpip parameters

    A socket program recently written in python has run with an error:
    socket.error: [Errno 10048] normally each socket address (protocol/network address/port) is allowed only once
    After searching, it is found that this prompt appears when the port is in conflict. The possible reason is that after a Socket is created in the server program and a port is opened, the Socket is not closed at the end of the program. Therefore, this error prompt will appear socket error 10048 python time the program is started.
    1, at the end of the server program to close the Socket
    2. Or change the port number
    3. Restart the machine
    Win7 system quickly check the port number and pid process number:
    1. Press Win+R key, enter CMD, open the command line.
    2. Enter netstat -aon

    Bind fails with error 98 (or error 10048)

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

    The Setup

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

    //Cross-platform error code #if defined(_WIN32) #define GETSOCKETERRNO() (WSAGetLastError()) #else #define GETSOCKETERRNO() (errno) #endif //Set port to bind to. struct addrinfo *address; getaddrinfo(0, "8080", &hints, &address); //Create socket. SOCKET socket_listen; socket_listen = socket(address->ai_family, address->ai_socktype, address->ai_protocol); //Bind socket to local port. if (bind(socket_listen, address->ai_addr, address->ai_addrlen)) { fprintf(stderr, "bind() failed. Error: %d\n", GETSOCKETERRNO()); return 1; }

    If your call to bind fails, the first thing to do is check the error code. The error is stored in on Linux, but on Windows you will need to error call to undefined function mysql_select_db in .

    If the error returned by 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. 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 google non-blocking connect so_error 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 command. The stands for "numeric tcp listen programs". In order words, we are asking 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 command on Linux to find which program is tying up port 8080.

    screenshot showing usage of netstat command to find which program <a href=errorkiller ver 2.6 serial using a given port">

    As you can see above, the program tying up port 8080 is "server1" with a PID of 96939. Knowing the PID, socket error 10048 python, 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 command, but the usage is different. On Windows you can show all listening sockets with the command. Window's command doesn't have an easy way to filter only listening sockets, so the 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 on Windows to see which program is using port 8080:

    screenshot showing usage of netstat on Windows to find 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 command. For example, running would get us the program name for PID 50396 — the process we identified as using port 8080. For example:

    screenshot showing tasklist to get program name from a PID

    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 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, socket error 10048 python. What is going on here?

    I won't go into too much depth here (read my book for that), socket error 10048 python, 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 anyway (typically). However, this TIME-WAIT state can be a problem for server applications, socket error 10048 python. 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 socket option before calling. It looks like this:

    int yes = 1; if (setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (void*)&yes, sizeof(yes)) < 0) { fprintf(stderr, socket error 10048 python, "setsockopt() failed. Error: %d\n", GETSOCKETERRNO()); }

    This option will allow to succeed even if a few TIME-WAIT connections are still around. There is very little downside to using the 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 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 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 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 socket error 10048 python 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 socket option on Linux. The 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.

    You can find the rest of my network programming articles here.

    Python Server Client program error: "OSError: [WinError 10048]"

    So I'm studying Python from the book Fundamentals of Python by Kenneth Lambert and I'm having trouble with an error from one of the programs in the book.

    Here in chapter 10 talks about Clients and Servers. My professor asked us to key those programs in Python to see how they work. The first programs worked perfectly, but in a program I'm getting an socket error 10048 python which seems to be a Windows error instead of a Python one.

    This is the program in page 339:

    When I run this program, it displays the "Waiting for connection" message in the Shell. However, when I try to connect to the program using the Command Prompt, it displays the following error:

    We haven't studied this in class a lot. So I'm just wondering why this happens and how to fix it.

    Thanks!

    socket error 10048 python asked May 11, 2014 at 17:54

    user avatar
    user3451338user3451338

    8911 gold badge11 silver badge77 socket error 10048 python badges

    2 Comments

    Leave a Comment