Esempio n. 1
0
 def handle(self):
     # self.request is the TCP socket connected to the client
     self.data = socket_utils.recv(self.request).strip()
     print "%s wrote:" % self.client_address[0]
     print self.data
     # just send back the same data, but upper-cased
     socket_utils.send(self.request, self.data.upper())
Esempio n. 2
0
 def send(self, socket):
     packet = struct.pack("<IB", self.len, self.type) + self.payload
     socket_utils.send(socket, packet)
Esempio n. 3
0
import socket
import sys
import socket_utils

HOST, PORT = "localhost", 9999
data = " ".join(sys.argv[1:])

# Create a socket (SOCK_STREAM means a TCP socket)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect to server and send data
sock.connect((HOST, PORT))
socket_utils.send(sock, data + "\n")

# Receive data from the server and shut down
received = socket_utils.recv(sock) 
sock.close()

print "Sent:     %s" % data
print "Received: %s" % received