organise files, use same port number in examples
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
import socket
|
||||
import sys
|
||||
|
||||
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)
|
||||
|
||||
try:
|
||||
# Connect to server and send data
|
||||
sock.connect((HOST, PORT))
|
||||
sock.sendall(bytes(data + "\n"))
|
||||
|
||||
# Receive data from the server and shut down
|
||||
received = str(sock.recv(1024));
|
||||
finally:
|
||||
sock.close()
|
||||
|
||||
print("Sent: {}".format(data))
|
||||
print("Received: {}".format(received))
|
||||
@@ -28,7 +28,7 @@ class MyTCPHandler(SocketServer.BaseRequestHandler):
|
||||
# self.wfile.write(self.data.upper())
|
||||
|
||||
if __name__ == "__main__":
|
||||
HOST, PORT = "localhost", 9999
|
||||
HOST, PORT = "localhost", 10000
|
||||
|
||||
# Create the server, binding to localhost on port 9999
|
||||
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import socket
|
||||
import sys
|
||||
|
||||
HOST, PORT = "localhost", 9999
|
||||
data = " ".join(sys.argv[1:])
|
||||
|
||||
# SOCK_DGRAM is the socket type to use for UDP sockets
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
# As you can see, there is no connect() call; UDP has no connections.
|
||||
# Instead, data is directly sent to the recipient via sendto().
|
||||
sock.sendto(data + "\n", (HOST, PORT))
|
||||
received = sock.recv(1024)
|
||||
|
||||
print "Sent: {}".format(data)
|
||||
print "Received: {}".format(received)
|
||||
Reference in New Issue
Block a user