示例#1
0
 def _send(self, packet, buffer=False):
     packet.ack_num = self.recv_window.confirmed
     if not buffer:
         print_info(self.name, 'sending', packet)
         self.socket.send(packet.encode())
     else:
         packet = self.send_window.put_packet(packet)
         print_info(self.name, 'buffered', packet)
示例#2
0
def two_ends():
    from adaptors import DropoutSocket, CorruptedSocket, DisorderSocket
    server = threading.Thread(target=start_server, args=())
    server.setDaemon(True)
    server.start()
    client_protocol = start_client(lambda x: DisorderSocket(0.5, x))

    client_protocol.send(b'hello, world1')
    client_protocol.send(b'hello, world2')
    client_protocol.send(b'hello, world3')
    client_protocol.send(b'hello, world4')
    client_protocol.flush()

    client_protocol.close()
    print_info('done')
示例#3
0
def start_server():
    global print_count
    server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    server.setblocking(False)
    server.bind(('0.0.0.0', SERVER_PORT))
    server.connect((CLIENT_IP, CLIENT_PORT))
    server_protocol = Protocol(server, name='server')
    while server_protocol.open:
        with endpoint_mutex:
            print_info("Server round")
            packet = server_protocol.recv()
            if packet:
                print_info('Server', packet)
                print_count += 1
        time.sleep(yield_time)
示例#4
0
    def _recv(self):
        if not self.open:
            raise ConnectionResetError('Connection reset')

        try:
            data = self.socket.recv(8192)
        except IOError as ex:
            if ex.errno == 11:
                return
            raise ex
        if not data:
            return

        packet = Packet().decode(data)
        if packet.chk_sum != packet.compute_checksum():
            print_info(self.name, 'Checksum error, discarding', packet)
            return

        print_info(self.name, 'received', packet)
        return packet
示例#5
0
 def recv(self, bufsize=8192):
     packet = self.socket.recv(bufsize)
     print_info(self, 'recv', packet)
     return packet
示例#6
0
 def send(self, data):
     print_info('Writing data', data)
示例#7
0
def test_byte_buf():
    buf = ByteBuf()
    buf.write_int(666)
    print_info(buf.read_int())
    buf.write_data(b'hello, world')
    print_info(buf.read_data())
# -----------------------------------------------------------------------------
# From Numpy to Python
# Copyright (2017) Nicolas P. Rougier - BSD license
# More information at https://github.com/rougier/numpy-book
# -----------------------------------------------------------------------------
import numpy as np
from tools import print_info

if __name__ == '__main__':
    Z = np.arange(5 * 5).reshape(5, 5)
    print_info(Z)
    # Z = np.array(Z,order='F')
    # info(Z)