Network Byte Order : Struct : Buildin Module PYTHON TUTORIALS


PYTHON TUTORIALS » Buildin Module » Struct »

 

Network Byte Order


#!/usr/bin/env python


import struct, sys

def htons(num):
    return struct.pack('!H', num)

def htonl(num):
    return struct.pack('!I', num)

def ntohs(data):
    return struct.unpack('!H', data)[0]

def ntohl(data):
    return struct.unpack('!I', data)[0]

def sendstring(data):
    return htonl(len(data)) + data

print "Enter a string:"
str = sys.stdin.readline().rstrip()

print repr(sendstring(str))



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Buildin Module
» Struct