2507 라용대 작품 제출 |
좋아요:0 | ||||
---|---|---|---|---|---|
작성자 | 라용대 | 등록일 | 19.12.26 | 조회수 | 145 |
첨부파일 |
|
||||
EMC 작품 제출합니다.
파이썬 채팅 코드
<서버>
from socket import * import threading import time
def send(sock): while True: sendData = input('>>>') sock.send(sendData.encode('utf-8'))
def receive(sock): while True: recvData = sock.recv(1024) print('상대방 :', recvData.decode('utf-8'))
port = 8081
serverSock = socket(AF_INET, SOCK_STREAM) serverSock.bind(('', port)) serverSock.listen(1)
print('%d번 포트로 접속 대기중...'%port)
connectionSock, addr = serverSock.accept()
print(str(addr), '에서 접속되었습니다.')
sender = threading.Thread(target=send, args=(connectionSock,)) receiver = threading.Thread(target=receive, args=(connectionSock,))
sender.start() receiver.start()
while True: time.sleep(1) pass <클라이언트> from socket import * import threading import time def send(sock): while True: sendData = input('>>>') sock.send(sendData.encode('utf-8')) def receive(sock): while True: recvData = sock.recv(1024) print('상대방 :', recvData.decode('utf-8')) port = 8081 clientSock = socket(AF_INET, SOCK_STREAM) clientSock.connect(('127.0.0.1', port)) print('접속 완료') sender = threading.Thread(target=send, args=(clientSock,)) receiver = threading.Thread(target=receive, args=(clientSock,)) sender.start() receiver.start() while True: time.sleep(1) pass |
이전글 | 10412 박순지 동아리 활동 보고서 |
---|---|
다음글 | 20425이현규 |