python&tensorflow&pytorch

socket example

tomato13 2011. 1. 10. 10:06

http://blog.naver.com/skyssib?Redirect=Log&logNo=50045112412


========= server ==================

import socket


HOST = '127.0.01'                 # Symbolic name meaning the local host

PORT = 50007              # Arbitrary non-privileged port

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.bind((HOST, PORT))

s.listen(1)

conn, addr = s.accept()

print 'Connected by', addr

while 1:

    data = conn.recv(1024)

    if not data: break

    conn.send('server: ' + data)

conn.close()


========= client =====================
# Echo client program
import socket

HOST = '127.0.0.1'    # The remote host
PORT = 50007              # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
while(1):
s.send('Hello, world')
data = s.recv(1024)
print 'Received', repr(data)
s.close()

'python&tensorflow&pytorch' 카테고리의 다른 글

string comparison  (0) 2011.01.18
python list length  (0) 2011.01.18
python list  (0) 2011.01.14
conversion from string to integer  (0) 2011.01.10
python thread  (0) 2011.01.10