728x90

server

import socket

HOST = ''

PORT = 50007

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 True:

data = conn.recv(1024)

if not data: break

conn.send(data)

conn.close()

 

client

import socket

 

HOST = '127.0.0.1'

PORT = 50007

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

s.connect((HOST, PORT))

s.send(b'hello, python')

data = s.recv(1024)

s.close()

print('Received' repr(data))

728x90

'Python' 카테고리의 다른 글

python 구글 메일 보내기  (0) 2014.05.23
python 메일 보내기  (0) 2014.05.10
python 제어문  (0) 2014.05.05
python 함수  (0) 2014.05.05
python shallow copy, deep copy  (0) 2014.05.05

+ Recent posts