Пример #1
0
    def extract(self,msg:Msg) -> str:
        return msg.data

    def isack(self,msg:Msg,seq:int):
        return msg.isack(seq)

    def make_pkt(self, data, checksum=None, seq=None):
        m = Msg(data, checksum, seq)
        return m

    def deliver_data(self,data:str,filename:str):
        try:
            with open(filename, 'a+') as f:
                f.write(data)
        except Exception as e:
            print('fail to deliver data')



isserver = False
if isserver:
    server = MyServer('127.0.0.1',10006)
    serverthread = runScriptThread(server.mainloop)
    serverthread.start()
    #serverthread.join()
else:
    client = MyClient('127.0.0.1',10005)
    clientthread = runScriptThread(client.mainloop)
    clientthread.start()
    #clientthread.join()
Пример #2
0
        return msg.notcorrupt()

    def extract(self,msg:Msg) -> str:
        return msg.data

    def isack(self,msg:Msg,seq:int):
        return msg.isack(seq)

    def make_pkt(self, data, checksum=None, seq=None):
        m = Msg(data, checksum, seq)
        return m

    def deliver_data(self,data:str,filename:str):
        try:
            with open(filename, 'a+') as f:
                f.write(data)
        except Exception as e:
            print('fail to deliver data')

isserver = False
if isserver:

    server = MyServer("127.0.0.1",10006)
    serverthread = runScriptThread(server.mainloop)
    serverthread.start()
    #serverthread.join()
else:
    client = MyClient('127.0.0.1',10005)
    clientthread = runScriptThread(client.mainloop)
    clientthread.start()
    #clientthread.join()
Пример #3
0
 def inits(self):
     MyServer.__init__(self)
     MyPlc.__init__(self)
def test_serv_obj_init(jimbeam, capsys, check_list_for_init):
    serv = MyServer()
    print(f'{serv._stop}, {serv._requests_list}, {serv._connections_list}')
    out, err = capsys.readouterr()
    for check_item in check_list_for_init:
        assert check_item in out
def serv_obj():
    return MyServer()
Пример #6
0
from twisted.internet import reactor
from twisted.python import log
from myserver import MyServer
import sys

def done(result):
    print "Key result:", result
    reactor.stop()

def setDone(result, server):
    server.get("a key").addCallback(done)

def bootstrapDone(found, server):
    server.set("a key", "a value").addCallback(setDone, server)

bt_list = [
        ("213.125.18.163", 14662),
        ("114.39.181.172", 11194),
        ("71.238.187.114", 4662),
        ("115.70.239.220", 3389),
        ("85.241.34.5", 61153)]
server = MyServer()
server.listen(8468)
server.bootstrap(bt_list).addCallback(bootstrapDone, server)

reactor.run()
Пример #7
0
from twisted.internet import reactor
from twisted.python import log
from myserver import MyServer
import sys


def done(result):
    print "Key result:", result
    reactor.stop()


def setDone(result, server):
    server.get("a key").addCallback(done)


def bootstrapDone(found, server):
    server.set("a key", "a value").addCallback(setDone, server)


bt_list = [("213.125.18.163", 14662), ("114.39.181.172", 11194),
           ("71.238.187.114", 4662), ("115.70.239.220", 3389),
           ("85.241.34.5", 61153)]
server = MyServer()
server.listen(8468)
server.bootstrap(bt_list).addCallback(bootstrapDone, server)

reactor.run()