本文介绍了Python sctp模块 - 服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试测试SCTP进行网络部署。
我没有SCTP服务器或客户端,希望能够使用pysctp。



我确信我有客户端代码工作。

  def sctp_client():
print(SCTP client)
sock = sctp.sctpsocket_tcp socket.AF_INET)
#sock.connect(('10.10.10.70',int(20003)))
sock.connect(('10.10.10.41',int(21000)))
print(Sending message)
sock.sctp_send(msg ='allowed')
sock.shutdown(0)
sock.close()

有没有人运用在服务器端使用python sctp模块?
谢谢Advance!

解决方案

我知道这个话题有点过时了,但是我想我会回应无论如何帮助社区。

简而言之:




  • 你正在使用套接字套件 pysctp 创建客户端或服务器;

  • 您可以按照通常的方式创建服务器连接将有一个常规的TCP连接。



这是一些代码让你开始,它有点冗长,但它说明了一个完整的连接,发送,接收和关闭连接。



您可以在您的开发计算机上运行它,然后使用如 ncat nmap 实现 netcat )连接,即: ncat - sctp localhost 80



不用多说,这里是代码... HTH:

 #这是我们SCTP需要的软件包erver 
import socket
import sctp
from sctp import *
import threading

#让我们创建一个套接字:
my_tcp_socket = sctpsocket_tcp .AF_INET)
my_tcp_port = 80

#这是服务器的两个参数
server_ip =0.0.0.0
backlog_conns = 3

#设置一个连接:
my_tcp_socket.events.clear()
my_tcp_socket.bind((server_ip,my_tcp_port))
my_tcp_socket.listen(backlog_conns)

#这是一个处理连接的方法:
def handle_client(client_socket):
client_socket.send(Howdy!你的名字是什么?\\\

name = client_socket.recv(1024)#这可能是一个具有reaaallly长名称的人的问题
name = name.strip()

print他的名字是Robert Paulson。呃,刮啊。它是{0}。格式(名称)
client_socket.send(感谢您的调用,{0}再见,现在。格式(名称))
client_socket.close()

#现在,我们来处理一个实际的连接:
while True:
client,addr = my_tcp_socket.accept()
print从{0}调用:{1 }。format(addr [0],addr [1])$ ​​b
$ b client_handler = threading.Thread(target = handle_client,
args =(client,))
client_handler。 start()


I have been trying to test SCTP for a network deployment.I do not have an SCTP server or client and was hoping to be able use pysctp.

I am fairly certain that I have the client side code working.

def sctp_client ():
    print("SCTP client")
    sock = sctp.sctpsocket_tcp(socket.AF_INET)
    #sock.connect(('10.10.10.70',int(20003)))
    sock.connect(('10.10.10.41',int(21000)))
    print("Sending message")
    sock.sctp_send(msg='allowed')
    sock.shutdown(0)
    sock.close()

Has anybody had luck with using the python sctp module for the server side?Thank you in Advance!

解决方案

I know that this topic's a bit dated, but I figured I would respond to it anyway to help out the community.

In a nutshell:

  • you are using pysctp with the sockets package to create either a client or a server;
  • you can therefore create your server connection as you normally would with a regular TCP connection.

Here's some code to get you started, it's a bit verbose, but it illustrates a full connection, sending, receiving, and closing the connection.

You can run it on your dev computer and then use a tool like ncat (nmap's implementation of netcat) to connect, i.e.: ncat --sctp localhost 80.

Without further ado, here's the code... HTH:

# Here are the packages that we need for our SCTP server
import socket
import sctp
from   sctp import *
import threading

# Let's create a socket:
my_tcp_socket = sctpsocket_tcp(socket.AF_INET)
my_tcp_port   = 80

# Here are a couple of parameters for the server
server_ip     = "0.0.0.0"
backlog_conns = 3

# Let's set up a connection:
my_tcp_socket.events.clear()
my_tcp_socket.bind((server_ip, my_tcp_port))
my_tcp_socket.listen(backlog_conns)

# Here's a method for handling a connection:
def handle_client(client_socket):
  client_socket.send("Howdy! What's your name?\n")
  name = client_socket.recv(1024) # This might be a problem for someone with a reaaallly long name.
  name = name.strip()

  print "His name was Robert Paulson. Er, scratch that. It was {0}.".format(name)
  client_socket.send("Thanks for calling, {0}. Bye, now.".format(name))
  client_socket.close()

# Now, let's handle an actual connection:
while True:
    client, addr   = my_tcp_socket.accept()
    print "Call from {0}:{1}".format(addr[0], addr[1])

    client_handler = threading.Thread(target = handle_client,
                                      args   = (client,))
    client_handler.start()

这篇关于Python sctp模块 - 服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-10 12:30