用python的twisted做个简单游戏服务器原形--客户端连接monitor管理类

本文介绍如何利用Python的Twisted库创建一个基本的游戏服务器原型,涉及客户端连接管理和消息队列处理。Monitor类作为客户端工厂,在连接建立和断开时进行相应操作,并通过MessageQueue线程处理客户端消息。
摘要由CSDN通过智能技术生成
'''
Created on 2012-8-14

@author: qs
'''
#from twisted.internet import epollreactor
#epollreactor.install()
from twisted.internet import selectreactor
selectreactor.install()

from twisted.internet.protocol import ClientFactory, Protocol
from twisted.internet import reactor
from buffer import Buffer
import struct
import sys
import threading
from msgqueue import MessageQueue


class Service(Protocol):

    def __init__(self):
        self.index = 0
        self.identify = 0
    
    def connectionMade(self):
        print "new client come!"
        self.factory.service_tick = self.factory.service_tick + 1
        self.identify = self.factory.service_tick
        self.factory.bind_service(self)

        
    def connectionLost(self, reason):
        print "new client lost"
        self.factory.unbind_service(self)
        
    def dataReceived(self, data):
        message = struct.pack
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值