def create_socket(host, port, blockSize=65536, timeout=NGAMS_SOCK_TIMEOUT_DEF):

    global g_udt_started
    global udt_start_lock

    udt_start_lock.acquire()
    try:
        if (not g_udt_started):
            udt4.startup()
            g_udt_started = True
    finally:
        udt_start_lock.release()

    print('create_client(%s, %s)' % (host, port))

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

    #print "UDT_SNDTIMEO = %d" % udt4.getsockopt(socket, udt4.UDT_SNDTIMEO)
    #print "UDT_RCVTIMEO = %d" % udt4.getsockopt(socket, udt4.UDT_RCVTIMEO)
    #
    # set sock options
    #
    if (not timeout or timeout < 0):
        loc_timeout = NGAMS_SOCK_TIMEOUT_DEF
    else:
        loc_timeout = timeout

    opts = [(udt4.UDP_SNDBUF, blockSize), (udt4.UDP_RCVBUF, blockSize),
            (udt4.UDT_SNDTIMEO, loc_timeout)]

    for opt in opts:
        udt4.setsockopt(socket, opt[0], opt[1])
    #print "UDT_SNDTIMEO = %d" % udt4.getsockopt(socket, udt4.UDT_SNDTIMEO)
    #print "UDT_RCVTIMEO = %d" % udt4.getsockopt(socket, udt4.UDT_RCVTIMEO)


#
#
#    udt4.setsockopt(socket, udt4.UDP_SNDBUF,640000)
#    udt4.setsockopt(socket, udt4.UDP_RCVBUF,640000)
#
#print "UDP_SNDBUF = %d" % udt4.getsockopt(socket, udt4.UDP_SNDBUF)
#print "UDP_RCVBUF = %d" % udt4.getsockopt(socket, udt4.UDP_RCVBUF)

#    udt4.setsockopt(socket, udt4.UDT_SNDBUF,64)
#    udt4.setsockopt(socket, udt4.UDT_RCVBUF,64)
    localhost = '146.118.84.66'
    udt4.bind(socket, localhost, port)

    #print('connecting client')
    udt4.connect(socket, host, port)
    #    try:
    #        udt4.connect(socket, host, port)
    #    except Exception as err:
    #        #print('Exception: %s' % err)
    #        raise err

    #print "%s ---------" % str(socket.UDTSOCKET)
    return socket
Exemple #2
0
def create_server(host, port):
    print('create_server(%s, %s)' % (host, port))
    
    global server 
    
    socket = udt4.socket(
            socklib.AF_INET, socklib.SOCK_STREAM, socklib.AI_PASSIVE
            ) 
    
    #
    # set sock options 
    #
    opts = [ (udt4.UDT_SNDBUF   , 64 * 1024),
             (udt4.UDT_RCVBUF   , 64 * 1024),
             (udt4.UDT_REUSEADDR, True     )
             ]

    #for opt in opts:
    #    udt4.setsockopt(socket, opt[0], opt[1])
    
    udt4.bind(socket, host, port)
    udt4.listen(socket, 10)
    
    server = socket

    return True 
Exemple #3
0
def create_server(host, port):
    print('create_server(%s, %s)' % (host, port))
    
    global server 
    
    socket = udt4.socket(
            socklib.AF_INET, 
           (socklib.SOCK_STREAM, socklib.SOCK_DGRAM)[mode == 'DGRAM'], 
            socklib.AI_PASSIVE
            ) 
    
    print(
            ('socklib.SOCK_STREAM', 'socklib.SOCK_DGRAM')[mode == 'DGRAM']
            )
    
    #
    # set sock options 
    #
    opts = [ (udt4.UDT_SNDBUF   , 64 * 1024),
             (udt4.UDT_RCVBUF   , 64 * 1024),
             (udt4.UDT_REUSEADDR, True     )
             ]

    for opt in opts:
        udt4.setsockopt(socket, opt[0], opt[1])
    
    udt4.bind(socket, host, port)
    udt4.listen(socket, 10)
    
    server = socket

    return True 
Exemple #4
0
    def bind(self, address):
        """
        Binds port to device associted with address and specific port.

        :param  address:    device ip port pair  
        :type   address:    tuple( str(), int() )
        """
        if self.__udpsock != None:
            self.__udpsock.bind(address)
        else:
            udt4.bind(self.__sock, str(address[0]), int(address[1]))
Exemple #5
0
    def bind(self, arg):
        """
        Binds the UDT socket to address and specific port OR binds 
        UDT directly on an existing UDP socket.

        :param  arg:    device ip port pair or an existing UDP socket  
        :type   arg:    tuple( str(), int() ) or a UDP socket.socket
        """
        if isinstance(arg,socklib.socket):
            udt4.bind_to_udp(self.__sock,arg.fileno())
        else:
            udt4.bind(self.__sock, str(arg[0]), int(arg[1]))
Exemple #6
0
    def bind(self, arg):
        """
        Binds the UDT socket to address and specific port OR binds 
	UDT directly on an existing UDP socket.

        :param  arg:    device ip port pair or an existing UDP socket  
        :type   arg:    tuple( str(), int() ) or a UDP socket.socket
        """
        if isinstance(arg, socklib.socket):
            udt4.bind_to_udp(self.__sock, arg.fileno())
        else:
            udt4.bind(self.__sock, str(arg[0]), int(arg[1]))
Exemple #7
0
    def runServer(self):
        udt.bind(self.sender, '127.0.0.1', 8002)
        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.sendmsg(client, buf, len(buf)), len(buf))
            else:
                self.assertEquals(udt.recvmsg(client, len(buf)), buf)
Exemple #8
0
    def runServer(self):
        udt.bind  (self.sender, '127.0.0.1', 8002)
        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.sendmsg(client, buf, len(buf)), len(buf)
                        )
            else:
                self.assertEquals(
                        udt.recvmsg(client, len(buf)), buf
                        )
Exemple #9
0
#!/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'