organise files, use same port number in examples
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/venv
|
||||||
|
/.pydevproject
|
||||||
|
/.project
|
||||||
@@ -20,5 +20,5 @@ class SecondaryServerSocket(asyncore.dispatcher_with_send):
|
|||||||
def handle_close(self):
|
def handle_close(self):
|
||||||
print "Disconnected from", self.getpeername( )
|
print "Disconnected from", self.getpeername( )
|
||||||
|
|
||||||
MainServerSocket(8881)
|
MainServerSocket(10000)
|
||||||
asyncore.loop( )
|
asyncore.loop( )
|
||||||
0
requirements.txt
Normal file
0
requirements.txt
Normal file
@@ -1,7 +1,7 @@
|
|||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
HOST, PORT = "localhost", 9999
|
HOST, PORT = "localhost", 10000
|
||||||
data = " ".join(sys.argv[1:])
|
data = " ".join(sys.argv[1:])
|
||||||
|
|
||||||
# Create a socket (SOCK_STREAM means a TCP socket)
|
# Create a socket (SOCK_STREAM means a TCP socket)
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import socket
|
import socket
|
||||||
import select
|
import select
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.bind(('', 8881))
|
sock.bind(('', 10000))
|
||||||
sock.listen(5)
|
sock.listen(5)
|
||||||
|
|
||||||
# lists of sockets to watch for input and output events
|
# lists of sockets to watch for input and output events
|
||||||
@@ -34,7 +34,9 @@ try:
|
|||||||
# a disconnect, give a message and clean up
|
# a disconnect, give a message and clean up
|
||||||
print "disconnected from", adrs[x]
|
print "disconnected from", adrs[x]
|
||||||
del adrs[x]
|
del adrs[x]
|
||||||
try: ous.remove(x)
|
try:
|
||||||
|
ins.remove(x)
|
||||||
|
ous.remove(x)
|
||||||
except ValueError: pass
|
except ValueError: pass
|
||||||
x.close( )
|
x.close( )
|
||||||
for x in o:
|
for x in o:
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class MyTCPHandler(SocketServer.BaseRequestHandler):
|
|||||||
# self.wfile.write(self.data.upper())
|
# self.wfile.write(self.data.upper())
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
HOST, PORT = "localhost", 9999
|
HOST, PORT = "localhost", 10000
|
||||||
|
|
||||||
# Create the server, binding to localhost on port 9999
|
# Create the server, binding to localhost on port 9999
|
||||||
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
|
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