# Collection of code snippets by Arne Vajhøj 
# (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import socket

HOST = 'localhost'
PORT = 12345
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
print('connected')
wf = s.makefile('w')
rf = s.makefile('r')
a = 123
b = 456
wf.write('%d %d\n' % (a, b))
wf.flush()
line = rf.readline().rstrip()
c = int(line)
print('%d' % (c))
v = 'ABC'
wf.write('%s\n' % (v))
wf.flush()
v2 = rf.readline().rstrip()
print(v2)
s.close()
