Server
# Client
from socket import *
import time
print("\n====================")
print(" CLIENT ")
print("====================\n")
clientSock = socket(AF_INET, SOCK_STREAM) # Make socket object
print("Wait for connenction ...")
clientSock.connect(('127.0.0.1', 8008)) # connet to self
print("Connected with Server :)\n")
time.sleep(1)
clientSock.send("Hello, I`m client !!".encode('utf-8'))
print("Send message.")
time.sleep(1)
RecvData = clientSock.recv(1024)
print("Received Data: ", RecvData.decode('utf-8'))
Client
# Server
from socket import *
import time
print("\n====================")
print(" SERVER ")
print("====================\n")
serverSock = socket(AF_INET, SOCK_STREAM) # make socket object
serverSock.bind(('', 8008)) # connect Socket number with real Address Family
serverSock.listen(1) # set number of client for accessing simultaneously
print("Wait for any connection request ...")
connectedSock, addr = serverSock.accept() # Accept and return New Socket & Address
print("Connected with [{}] :)\n".format(str(addr)))
time.sleep(1)
RecvData = connectedSock.recv(1024)
print("Received Data: ", RecvData.decode('utf-8'))
time.sleep(1)
connectedSock.send("Hello, I`m a server :)".encode('utf-8'))
print("Send message.")
'Network' 카테고리의 다른 글
XSS & CSRF (0) | 2021.03.03 |
---|---|
네트워크관리사 2급 (0) | 2021.01.23 |