-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
20 lines (17 loc) · 834 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import socket
SRV_ADDR = input("Type the server IP address: ")
SRV_PORT = int(input("Type the server port: "))
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #create new socket using the default family (AF_INET) that uses TCP and the default socket type connection-oriented (SOCK_STREAM).
s.bind((SRV_ADDR, SRV_PORT))
s.listen(1)
print("Server started! Waiting for connections...")
connection, address = s.accept()
print('Client connected with address:', address)
while 1:
data = connection.recv(1024)
if not data: break
connection.sendall(b'-- Message Received --\n')
print(data.decode('utf-8'))
connection.close
#run ifconfig use IPv4 address in Ethernet adapter vEthernet (WSL) for your server
#client side use netcat nc <ip> <port> same that you entered on your server, use client to send messages back.