yongyong-e
[Network] TCP simple example 본문
# Server
# serverTest.py
from socket import *
HOST = '192.168.0.10'
PORT = 50005
ADDR = (HOST, PORT)
BUFF_SIZE = 1024
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(ADDR)
serverSocket.listen(5)
clientSocket, addr = serverSocket.accept()
client_msg = clientSocket.recv(BUFF_SIZE)
print('client : ', client_msg.decode())
server_msg = 'server message'
clientSocket.send(server_msg.encode())
print('(check) ' + server_msg + ' transfer complete')
clientSocket.close()
# Client
# clientTest.py
from socket import *
HOST = '192.168.0.10'
PORT = 50005
ADDR = (HOST, PORT)
BUFF_SIZE = 1024
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect(ADDR)
client_msg = 'client message'
clientSocket.send(client_msg.encode())
print('(check) ' + client_msg + ' transfer complete')
server_msg = clientSocket.recv(BUFF_SIZE)
print('server : ', server_msg.decode())
clientSocket.close()
'프로그래밍 > Python' 카테고리의 다른 글
[Algorithm] 문자열 뒤집기 (0) | 2017.09.01 |
---|---|
[Network] TCP multi-Thread (3) | 2017.08.12 |
[Network] TCP file Transfer - 2 (0) | 2017.08.11 |
[Network] TCP file Transfer - 1 (0) | 2017.08.10 |
[Ubuntu16.04] PyCharm Python IDE 설치 (0) | 2017.08.08 |
Comments