[Errno 48] Address already in use 解决方法

在进行socket编程时,我们在运行server端代码的时候遇到了如下的问题:
这里写图片描述

显示地址已经被占用,那么我们如何解决这个问题?

首先我们看一下server端的代码:

s = socket.socket()
host = socket.gethostname()
port = 12345
s.bind((host,port))
s.listen(5)

Use lsof -i :5000 This will give you a list of processes using the port if any. Once the list of processes is given, use the id on the PID column to terminate the process: e.