diff --git a/sctp_client.py b/sctp_client.py index 5533926..48ab928 100644 --- a/sctp_client.py +++ b/sctp_client.py @@ -1,14 +1,28 @@ +from os import wait import socket import sctp +import time -sk = sctp.sctpsocket_tcp(socket.AF_INET) -sk.connect(("192.168.100.9", 36412)) +cli = sctp.sctpsocket_udp(socket.AF_INET) +tmp = sctp.event_subscribe(cli) +tmp.set_association(1) +tmp.set_data_io(1) -print("Sending Message") +cli.autoclose = 0 # no automatic closing of the associacion -sk.sctp_send(msg='hello world') -sk.shutdown(0) +cli_ = sctp.sctpsocket_udp(socket.AF_INET) +tmp = sctp.event_subscribe(cli_) +tmp.set_association(1) +tmp.set_data_io(1) +cli.bind(("127.0.0.1", 10001)) +cli_.bind(("127.0.0.1", 10002)) +cli.sctp_send(msg=b'0', to=("127.0.0.1", 10000)) +cli_.sctp_send(msg=b'0', to=("127.0.0.1", 10000)) +time.sleep(10) -sk.close() +cli.close() +time.sleep(3) +cli_.close() + \ No newline at end of file diff --git a/sctp_server.py b/sctp_server.py index e78f9a5..c531d9c 100644 --- a/sctp_server.py +++ b/sctp_server.py @@ -2,50 +2,27 @@ import sctp import config import json +import time -client_base = { "clients": - [ - { - "address": "192.168.0.24", - "port": "2006", - "nickname": "bulasie", - "online": True - }, - { - "address": "192.168.0.25", - "port": "2106", - "nickname": "bamboleo", - "online": False - }, - ] -} - -sock = sctp.sctpsocket_tcp(socket.AF_INET) -sock.bind((host, config.MULTICAST_PORT)) -sock.listen(1) +addr_server = ('127.0.0.1', 10000) +srv = sctp.sctpsocket_udp(socket.AF_INET) +tmp = sctp.event_subscribe(srv) +tmp.set_association(1) +tmp.set_data_io(1) +#srv.events = sctp.event_subscribe(srv) +srv.autoclose = 360 +srv.bind(addr_server) +srv.listen(5) + +while True: + #srv_to_cli, _addr_client = srv.accept() + try: + fromaddr, flags, msgret, notif = srv.sctp_recv(2048) + _ = "up" if notif.state==0 else "down" + print(f"assoc: {notif.assoc_id} -> {_}") + print('===============================================') + except: + pass -while True: - # wait for a connection - print ('waiting for a connection') - connection, client_address = sock.accept() +srv.close() - try: - # show who connected to us - print ('connection from', client_address) - # print connection - # receive the data in small chunks and print it - while True: - data, address = sock.recvfrom(999) - if data: - # output received data - print ("Data: %s" % data) - connection.sendall("We received " + str(len(data)) + " bytes from you") - print ("sending acknowledgement to ", address) - sock.sendto(json.dumps(client_base).encode('utf-8'), address) - else: - # no more data -- quit the loop - print ("no more data.") - break - finally: - # Clean up the connection - connection.close()