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
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
def setsockopt(self, option, value): """ :param option Intrinsic class constant ie: pyudt4.UDT_RCVBUF :type option int() :param value Variable type value. :type value bool(), int(), long(), or tuple() Sets a socket option to the specified type. """ udt4.setsockopt(self.__sock, option, value)