[英]Connecting to Openshift Python socket server via Adobe Air client
[英]Python client socket event handling like that found in Adobe ActionScript
我正在將一些ActionScript代碼移植到Python,並且正在嘗試某種類似於Flash(flash.events.EventDispatcher)中可用的事件調度程序實現。
我需要創建到服務器的客戶端套接字連接,該服務器將以橫幅形式響應。 然后,客戶端將發送一些信息,接收新的橫幅等。
我知道如何創建客戶端套接字,但是問題是如何處理事件,以便客戶端根據事件運行適當的功能。
我已經閱讀了一些有關Asyncore和Twisted等各種模塊的信息,說實話,我正在尋找一種快速且易於實現的模塊。 我需要以最小的麻煩將代碼移植為概念證明。
這是我使用asyncore的代碼的一部分:
import socket
import asyncore
class Client(asyncore.dispatcher):
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, port))
def handle_connect(self):
self.log('Socket connected')
def handle_close(self):
print "Socket disconnected"
self.close()
def handle_read(self):
print 'Received: ', self.recv(1024)
self.handle_close()
def connect(host, port)
clientSocket = Client(host, port)
asyncore.loop()
由於某種原因,代碼返回以下錯誤:
warning: unhandled write event
warning: unhandled write event
warning: unhandled write event
...
上面的代碼實際上並沒有做任何有用的事情。 我需要為IO錯誤以及用於處理來回發送的數據添加事件處理程序。 但是,首先,我需要整理基礎知識。
任何幫助是極大的贊賞。 謝謝。
如asyncore文檔中所述,您是否嘗試覆蓋handle_write
事件?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.