gpt4 book ai didi

python - 扭曲的 16 线接收器 : No callbacks fired

转载 作者:太空宇宙 更新时间:2023-11-04 05:32:55 26 4
gpt4 key购买 nike

我运行一个有点扭曲的应用程序大约一年了。一切都很好,直到 2 月底。从那时起,我无法在我的客户端和服务器之间传输任何数据。我根据我的真实代码准备了一个小例子:

服务器:

from twisted.python.filepath import FilePath
from twisted.logger import Logger, textFileLogObserver, globalLogPublisher, globalLogBeginner
from twisted.internet.endpoints import SSL4ServerEndpoint
from twisted.internet.ssl import PrivateCertificate, Certificate
from twisted.internet.defer import Deferred
from twisted.internet.task import react
from twisted.internet.protocol import Factory
from twisted.protocols.basic import LineReceiver
import codecs
import sqlite3
import os


import sys
globalLogBeginner.beginLoggingTo([textFileLogObserver(sys.stdout)])
loggy = Logger()

class Ex_Factory(Factory):
def __init__(self, loggy):
self.loggy = loggy
def buildProtocol(self, addr):
return Ex_Protocol(self.loggy)
class Ex_Protocol(LineReceiver):
def dataReceived(self,data):
self.loggy.info('mmm')
def connectionMade(self):
self.sendLine(b'hello')
self.loggy.info('ConMade')
def __init__(self, loggy):
self.loggy = loggy
self.loggy.info('Works')

def lineReceived(self, data):
self.loggy.info('I am not called! But why?')

def main(reactor):
#Set up a SSL-Endpoint
pemBytes = FilePath(b"private.pem").getContent()
certificateAuthority = Certificate.loadPEM(pemBytes)
myCertificate = PrivateCertificate.loadPEM(pemBytes)
serverEndpoint = SSL4ServerEndpoint(
reactor, 1234, myCertificate.options(certificateAuthority)
)
serverEndpoint.listen(Ex_Factory(loggy))
return Deferred()
react(main, [])

客户:

dir="/working_dir"
certname="private.pem"

from twisted.python.filepath import FilePath
from twisted.internet.endpoints import SSL4ClientEndpoint
from twisted.internet.ssl import (PrivateCertificate, Certificate, optionsForClientTLS)
from twisted.internet.defer import Deferred, inlineCallbacks
from twisted.internet.task import react
from twisted.internet.protocol import Factory
from twisted.protocols.basic import LineReceiver
import os
class SendAnyData(LineReceiver):
deferred = Deferred()
def connectionMade(self):
print('ConMade!')
self.sendLine(b"START")
self.transport.write(b"START\r\n")
def connectionLost(self, reason):
print('ConLost!')
self.deferred.callback(None)
def lineReceived(self, data):
line = data.decode("UTF-8")

@inlineCallbacks
def main(reactor):
def getServerandPort(i):
return ("1.2.3.4",1234)
pem = FilePath(b"Certificates/"+certname.encode("UTF-8")).getContent()
caPem = FilePath(b"Certificates/ca-private-cert.pem").getContent()
host, port = getServerandPort(0)

clientEndpoint = SSL4ClientEndpoint(
reactor, host, port,
optionsForClientTLS(u"ABC", Certificate.loadPEM(caPem),
PrivateCertificate.loadPEM(pem)),
)
factory = Factory.forProtocol(SendAnyData)
proto = yield clientEndpoint.connect(factory)
yield proto.deferred

os.chdir(dir)
react(main)

当我在 Debian Jessie 上使用 Python 3.4.2 在两个独立的 Raspberry Pis 上运行应用程序时,这是服务器的输出:

2016-04-09T11:44:01+0200 [-] Ex_Factory (TLS) starting on 1234
2016-04-09T11:44:01+0200 [__main__.Ex_Factory#info] Starting factory <__main__.Ex_Factory object at 0xb5f2ee50>
2016-04-09T11:44:49+0200 [__main__#info] Works
2016-04-09T11:44:49+0200 [__main__#info] ConMade
^C2016-04-09T11:46:54+0200 [-] Received SIGINT, shutting down.
2016-04-09T11:46:54+0200 [twisted.protocols.tls.TLSMemoryBIOFactory] (TLS Port 1234 Closed)
2016-04-09T11:46:54+0200 [__main__.Ex_Factory#info] Stopping factory <__main__.Ex_Factory object at 0xb5f2ee50>
2016-04-09T11:46:54+0200 [-] Main loop terminated.

为什么没有从客户端成功发送到服务器的行(“START”)?我做错了什么?

非常感谢您的帮助。

最佳答案

幸运的是,我在 twisted ticket system 中得到了 tom.prince 的帮助.他建议我打印出 connectionLost 回调的原因参数。我收到一个 SSLv3 错误,这导致我遇到了问题:证书已过期...

关于python - 扭曲的 16 线接收器 : No callbacks fired,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36515258/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com