Skip to content
Snippets Groups Projects
Commit aca0c195 authored by Faris Hasim Syauqi's avatar Faris Hasim Syauqi
Browse files

init server & client

parent a57d5cdb
No related merge requests found
import socket
SERVER_PORT = 10000
HOST_NAME = socket.gethostname()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST_NAME, SERVER_PORT))
while True:
msg = s.recv(8)
print(msg.decode("utf-8"))
\ No newline at end of file
import socket
SERVER_PORT = 10000
HOST_NAME = socket.gethostname()
HOST_ADDRESS = socket.gethostbyname(HOST_NAME)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST_NAME, SERVER_PORT))
s.listen(5)
print(f"Server listening on {HOST_ADDRESS}:{SERVER_PORT}")
while True:
clientsocket, address = s.accept()
print(f"Connection from {address} has been established!")
clientsocket.send(bytes("Welcome to the server!", "utf-8"))
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment