简体   繁体   English

Python2.6 SCTP通过sctp套接字发送和接收十六进制值

[英]Python2.6 SCTP send and recieve hex values through sctp sockets

I am trying to do sctp programming using Python2.6 and pysctp package. 我正在尝试使用Python2.6pysctp软件包进行sctp编程。 I was able to capture the message from the server but was not able to extract the hex dump of the received message from sctp socket. 我能够从服务器捕获消息,但无法从sctp套接字提取接收到的消息的十六进制转储。 And how to send my responseHex as response using the same socket to the connected server. 以及如何使用相同的套接字将我的responseHex作为响应发送到连接的服务器。

Assume my server is independent of this client and it continuously trying to connect with the 192.168.10.13 address. 假设我的服务器独立于该客户端,并且它不断尝试与192.168.10.13地址连接。

Code: 码:

#!/usr/bin/python

import sys
import socket
import pysctp
import pysctp.sctp as sctp

MAXRECVBUFFERSIZE = 2048
bindingIp  = "192.168.10.13"
socketPort = 112233;
socket     = sctp.sctpsocket_tcp(socket.AF_INET);

responseHex =[0xd0, 0x36, 0x02, 0x5a, 0x00, 0x51, 0x03, 0x00, 0x15, 0x00, 0x08, 0x00, 0x11];

socket.events.clear();
socket.bind((bindingIp, socketPort));
socket.listen(3);

client, addr = socket.accept();
buffer = client.recv(MAXRECVBUFFERSIZE);
print buffer   // This prints binary dump on the terminal
// And I want to send hexResponse variable through the same socket

socket.close();
exit(0)

First thing, remember not to put semicolons on the end of your statements. 首先,请记住不要在语句的末尾加上分号。 You don't need exit(0) at the end of the file either. 您也不需要文件末尾的exit(0)。

To get a hex dump, of "buffer", you can say: print map(hex, buffer) 要获得“缓冲区”的十六进制转储,您可以说: print map(hex, buffer)

To send your hex response, the easiest way would be to alter the definition of responseHex to look like this: 要发送十六进制响应,最简单的方法是将responseHex的定义更改为如下所示:

responseHex = '\\xd0\\x36\\x02\\x5a\\x00\\x51\\x03\\x00\\x15\\x00\\x08\\x00\\x11'

Then it should be able to be passed to the client.send() function. 然后应该可以将其传递给client.send()函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM