언어/python

python Network

파아랑새 2016. 3. 24. 22:11

아직 네트워크에 대해 잘 모르기 때문에 나중을 위해서 기록

server

import socket

s= socket.socket()
host = socket.gethostname()
port = 12345
s.bind((host, port))

s.listen(5)

while True:
c, addr = s.accept()
print ("Got connection", addr)
c.send("Thank you for connecting".encode())
c.close()


client

import socket

s = socket.socket()
host = socket.gethostname()
port = 12345

s.connect((host,port))
print(s.recv(1234))
s.close