TCP Communication
Sending
(to be written)
Receiving
Here's simple code to serve TCP in Python:
Toggle line numbers
1 #!/usr/bin/env python
2
3 import socket
4
5
6 TCP_IP = '127.0.0.1'
7 TCP_PORT = 5005
8
9 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
10 s.bind((TCP_IP, TCP_PORT))
11 s.listen(1)
12
13 conn, addr = s.accept()
14 print 'Connection address:', addr
15 while 1:
16 data = conn.recv(10) # buffer size is 10 bytes
17 if not data: break
18 print "received data:", data
19 conn.send(data) # echo
20 conn.close()
See also: UdpCommunication
Discussion
- (none yet!)