示例#1
0
文件: client.py 项目: gaochunzy/PyUDT
def test0():
    print('client: test0')
    
    if mode == 'DGRAM':
        dat = udt4.recvmsg(client, 4) 
        msg = udt4.recvmsg(client, struct.unpack('I', dat)[0])
    else:
        dat = udt4.recv(client, 4)
        msg = udt4.recv(client, struct.unpack('I', dat)[0])
示例#2
0
文件: client.py 项目: Nolhian/PyUDT
def test0():
    print("client: test0")

    if mode == "DGRAM":
        dat = udt4.recvmsg(client, 4)
        msg = udt4.recvmsg(client, struct.unpack("I", dat)[0])
    else:
        dat = udt4.recv(client, 4)
        msg = udt4.recv(client, struct.unpack("I", dat)[0])
示例#3
0
def test1():
    print('client: test1')

    if mode == 'DGRAM':
        dat = udt4.recvmsg(client, 4)
        msg = udt4.recvmsg(client, struct.unpack('I', dat)[0])
    else:
        dat = udt4.recv(client, 4)
        msg = udt4.recv(client, struct.unpack('I', dat)[0])

    print('test1: %i %s' % (len(msg), msg))
示例#4
0
文件: client.py 项目: Nolhian/PyUDT
def test1():
    print("client: test1")

    if mode == "DGRAM":
        dat = udt4.recvmsg(client, 4)
        msg = udt4.recvmsg(client, struct.unpack("I", dat)[0])
    else:
        dat = udt4.recv(client, 4)
        msg = udt4.recv(client, struct.unpack("I", dat)[0])

    print("test1: %i %s" % (len(msg), msg))
示例#5
0
文件: client.py 项目: BrockChen/PyUDT
def test1():
    print('client: test1')
    
    if mode == 'DGRAM':
        dat = udt4.recvmsg(client, 4)
        msg = udt4.recvmsg(client, struct.unpack('I', dat)[0])
    else:
        dat = udt4.recv(client, 4)
        msg = udt4.recv(client, struct.unpack('I', dat)[0])
        
    print(
        'test1: %i %s' % (len(msg), msg)
            )
示例#6
0
    def recv(self, size):
        """
        Receive data from socket.

        @return str(returned_data) 
        """
        return udt4.recv(self.__sock, size)
示例#7
0
def reliableUDTRecv(udtsocket, buff_len):
    """
    udtsocket     UDT Socket
    buff_len      int
    Return        buffer read (String)
    """
    buf_list = []
    read = 0
    toread = buff_len
    ret = 0

    while (toread):
        tmp_buff = None
        try:
            tmp_buff = udt4.recv(udtsocket, toread)
        except Exception, eee:
            print "%s Exception in reading data from UDT socket" % str(
                udtsocket.UDTSOCKET)
            raise eee

        if (not tmp_buff):
            return -1
        buf_list.append(tmp_buff)
        ret = len(tmp_buff)
        read += ret
        toread -= ret
示例#8
0
文件: pyudt.py 项目: bchretien/PyUDT
    def recv(self, size):
        """
        Receive data from socket.

        @return str(returned_data) 
        """
        return udt4.recv(self.__sock, size)
示例#9
0
    def runTest(self):
        Thread(target=self.runServer).start()

        udt.connect(self.recevr, '127.0.0.1', 8001)

        for k, i in enumerate([('a', 1), ('b', 2), ('c', 3)]):
            buf = i[0] * (10**i[1])

            if k % 2 != 0:
                self.assertEquals(udt.send(self.recevr, buf, len(buf)),
                                  len(buf))
            else:
                self.assertEquals(udt.recv(self.recevr, len(buf)), buf)
示例#10
0
    def runServer(self):
        udt.bind(self.sender, '127.0.0.1', 8001)
        udt.listen(self.sender, 10)

        client, host = udt.accept(self.sender)

        for k, i in enumerate([('a', 1), ('b', 2), ('c', 3)]):
            buf = i[0] * (10**i[1])

            if k % 2 == 0:
                self.assertEquals(udt.send(client, buf, len(buf)), len(buf))
            else:
                self.assertEquals(udt.recv(client, len(buf)), buf)
示例#11
0
    def runTest(self):
        Thread(target = self.runServer).start()
        
        udt.connect(self.recevr, '127.0.0.1', 8001)
        
        for k, i in enumerate([('a', 1), ('b', 2), ('c', 3)]):
            buf = i[0] * (10 ** i[1]) 

            if k % 2 != 0:
                self.assertEquals(
                        udt.send(self.recevr, buf, len(buf)), len(buf)
                        )
            else:
                self.assertEquals(
                        udt.recv(self.recevr, len(buf)), buf
                        )
示例#12
0
    def runServer(self):
        udt.bind  (self.sender, '127.0.0.1', 8001)
        udt.listen(self.sender, 10) 

        client, host = udt.accept(self.sender)

        for k, i in enumerate([('a', 1), ('b', 2), ('c', 3)]):
            buf = i[0] * (10 ** i[1]) 

            if k % 2 == 0:
                self.assertEquals(
                        udt.send(client, buf, len(buf)), len(buf)
                        )
            else:
                self.assertEquals(
                        udt.recv(client, len(buf)), buf
                        )
示例#13
0
import socket as socklib
import udt4
import struct

udt4.startup()

socket = udt4.socket(socklib.AF_INET, socklib.SOCK_STREAM, 0)

try:
    udt4.connect(socket, '127.0.0.1', 3001)
except RuntimeError as err:
    print(err)
    import sys
    sys.exit(0)

# recv message #
msg_len = struct.unpack('I', udt4.recv(socket, 4))[0]
message = udt4.recv(socket, msg_len)

print('received message: %s' % message)
assert len(message) == msg_len, 'invalid message received 0'

# send message #
message = 'no bottle found'
udt4.send(socket, struct.pack('I', len(message)), 4)
udt4.send(socket, message, len(message))

# cleanup #
udt4.close(socket)
udt4.cleanup()
示例#14
0
文件: server.py 项目: BrockChen/PyUDT
#!/usr/bin/env python 

import socket as socklib
import struct
import udt4 

socket = udt4.socket(socklib.AF_INET, socklib.SOCK_STREAM, 0)

udt4.bind(socket, '127.0.0.1', 3001)
udt4.listen(socket, 10)

sock, host = udt4.accept(socket)

# send message #
message = 'message in a bottle'

udt4.send(sock, struct.pack('I', len(message)), 4)
udt4.send(sock, message, len(message))


# recv message #
msg_len = struct.unpack('I', udt4.recv(sock, 4))[0]

message = udt4.recv(sock, msg_len) 

print(
    'received message: %s' % message
    )

assert len(message) == msg_len, 'invalid message'