1

I am trying to do sctp programming using Python2.6 and pysctp package. 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. And how to send my responseHex as response using the same socket to the connected server.

Assume my server is independent of this client and it continuously trying to connect with the 192.168.10.13 address.

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)
Ashwin
  • 993
  • 1
  • 16
  • 41

1 Answers1

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.

To get a hex dump, of "buffer", you can say: 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 = '\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.

Andrew Bainbridge
  • 4,651
  • 3
  • 35
  • 50