扭曲的Python服务器端口已在使用中

编程入门 行业动态 更新时间:2024-10-26 14:32:28
本文介绍了扭曲的Python服务器端口已在使用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

(顺便说一句,使用Mac)

我正在学习this构建扭曲的python套接字服务器的教程,一切都很顺利。

我面临的一个问题是我不知道如何关闭服务器。基本上,我更改了我的python脚本中的一些代码,我想重启服务器,但我不知道如何重启。我尝试从我的活动监视器中终止所有的python进程,但是当我再次尝试运行服务器时,我得到一个错误,即服务器无法在端口80上侦听。

脚本如下:

from twisted.internet.protocol import Factory, Protocol from twisted.internet import reactor class IphoneChat(Protocol): def connectionMade(self): self.factory.clients.append(self) print "clients are ", self.factory.clients def connectionLost(self, reason): self.factory.clients.remove(self) def dataReceived(self, data): a = data.split(':') print a if len(a) > 1: command = a[0] content = a[1] msg = "" if command == "iam": self.name = content msg = self.name + " has joined" elif command == "msg": msg = self.name + ": " + content print msg for c in self.factory.clients: c.message(msg) def message(self, message): self.transport.write(message + ' ') factory = Factory() factory.protocol = IphoneChat factory.clients = [] reactor.listenTCP(80, factory) print "Iphone Chat server started" reactor.run() 回溯(最近一次调用): 文件"pythonSocketServer.py",第39行,位于 Reacter.listenTCP(80,出厂) 文件"/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/posixbase.py",行495,在listenTcp中 P.startListing() 文件"/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/tcp.py",第980行,在开始侦听中 引发CannotListenError(self.interface,self.port,le) Twisted.interet.error.CannotListenError:无法侦听已在使用的任何:80:[Errno 48]地址。

推荐答案

使用netstat -nlp | grep 80查找使用端口80的进程。

如果可能,请使用kill -9 pid终止进程。

或者您可以使用其他端口,如12345。

factory = Factory() factory.protocol = IphoneChat factory.clients = [] reactor.listenTCP(12345, factory)

更多推荐

扭曲的Python服务器端口已在使用中

本文发布于:2023-08-07 03:34:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1316733.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:已在   端口   服务器   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!