#!/usr/bin/python
# -*- coding: utf-8 -*-
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()
# -*- coding: utf-8 -*-
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 `sendstring(str)`
本文转sinojelly51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/406615,如需转载请自行联系原作者