def main(settings): udt4.startup() if not create_server(settings['host'], settings['port']): print('failed to create_server') return 0 else: print('server socket created successfully') sock = accept_client() recv_file(sock) udt4.close(sock) udt4.close(server) udt4.cleanup()
def main(settings): udt4.startup() if not create_server(settings["host"], settings["port"]): print("failed to create_server") return 0 else: print("server socket created successfully") sock = accept_client() recv_file(sock) udt4.close(sock) udt4.close(server) udt4.cleanup()
def main(): """ """ udt.startup() udt_serv, udt_clients = acquire_udt_clients('127.0.0.1', 4001, 3) tcp_serv, tcp_clients = acquire_tcp_clients('127.0.0.1', 4002, 3) print('Configuring epoll') epoll = configure_epoll(udt_clients, tcp_clients) print('Reading messages') i = 0 while True: sets = epoll.wait(True, False, 10000, True, False) handle_socket_uset(epoll, sets[0]) handle_socket_uset(epoll, sets[1]) handle_socket_sset(epoll, sets[2]) handle_socket_sset(epoll, sets[3]) if len(sets[0]) == 0: i += 1 if i == 12: print('... done!') break print('Cleaning epoll') clean_epoll(epoll, udt_clients, tcp_clients) print('Closing sockets') for client in udt_clients: client.close() for client in tcp_clients: client.close() udt_serv.close() tcp_serv.close() udt.cleanup()
def main(settings): global mode mode = settings['mode'] udt4.startup() if not create_server(settings['host'], settings['port']): print('failed to create_server') return 0 else: print('server socket created successfully') sock = accept_client() test0(sock) test1(sock) test2(sock) udt4.close(sock) udt4.close(server) udt4.cleanup()
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()
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()