From 9a23935fafb2316315a009c94e17791277cabed4 Mon Sep 17 00:00:00 2001 From: DevOps User Date: Mon, 21 Jun 2021 12:00:45 +0200 Subject: [PATCH] sctp --- sctp_client.py | 14 ++++++++++++++ sctp_server.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 sctp_client.py create mode 100644 sctp_server.py create mode 100644 setup.py diff --git a/sctp_client.py b/sctp_client.py new file mode 100644 index 0000000..5533926 --- /dev/null +++ b/sctp_client.py @@ -0,0 +1,14 @@ +import socket +import sctp + +sk = sctp.sctpsocket_tcp(socket.AF_INET) +sk.connect(("192.168.100.9", 36412)) + + +print("Sending Message") + +sk.sctp_send(msg='hello world') +sk.shutdown(0) + + +sk.close() diff --git a/sctp_server.py b/sctp_server.py new file mode 100644 index 0000000..e78f9a5 --- /dev/null +++ b/sctp_server.py @@ -0,0 +1,51 @@ +import socket +import sctp +import config +import json + +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) + +while True: + # wait for a connection + print ('waiting for a connection') + connection, client_address = sock.accept() + + 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() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4bc79c5 --- /dev/null +++ b/setup.py @@ -0,0 +1,52 @@ +""" +setup.py + +Created by Philippe Langlois on 2009-11-02. +Copyright (c) 2009 Philippe Langlois. All rights reserved. + +This library is free software; you can redistribute it and/or modify it +under the terms of the GNU Lesser General Public License as published by the +Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +This library is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +details. + +You should have received a copy of the GNU Lesser General Public License +along with this library; If not, see . + +""" + +import setuptools +from distutils.core import setup, Extension + +setup(name='pysctp', + version='0.6.1', + license = "LGPL", + description = 'pysctp is a python module for the SCTP protocol stack and library. ', + long_description = 'pysctp is a python module for the SCTP protocol stack and library. It is the socket API implementation, not the SCTPlib implementation (this latest one is not supported anymore by their original developers). On Mac OS X you will need the SCTP NKE (Kernel Extensions) to make it work, use: http://sctp.fh-muenster.de/sctp-nke.html. On Debian-based systems, you need a SCTP-aware kernel (most are) and install the following packages: apt-get install libsctp-dev libsctp1 lksctp-tools', + url = "https://github.com/p1sec/pysctp", + keywords = "SCTP SIGTRAN", + platforms = ["Linux", "Debian", "Ubuntu", "Mac OS X (tested on 10.4)"], + classifiers = ['Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)', + 'Programming Language :: C', + 'Programming Language :: Python', + 'Topic :: Software Development :: Libraries :: Python Modules', + 'Topic :: System :: Networking' ], + py_modules=['sctp'], + ext_modules=[Extension('_sctp', sources=['_sctp.c'], + include_dirs=['.', '/usr/include'], + libraries=['sctp'], + library_dirs=['/usr/lib/', '/usr/local/lib/'], + ) + ], + data_files=[('include', ['_sctp.h'])], + author='Elvis Pfutzenreuter', + author_email='epx@epx.com.br', + maintainer='Benoit Michau', + maintainer_email='benoit.michau@p1sec.com', + )