-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
56 lines (38 loc) · 1.19 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
print("""\n\n
__ __ __ ____
_____/ /_ ____ _/ /_ / /_ ___ / / /
/ ___/ __ \/ __ `/ __/ / __ \/ _ \/ / /
/ /__/ / / / /_/ / /_ / / / / __/ / /
\___/_/ /_/\__,_/\__/ /_/ /_/\___/_/_/
\n\n\n""")
import time
import socket
import sys
new_socket = socket.socket()
host_name = socket.gethostname()
s_ip = socket.gethostbyname(host_name)
port = 8080
new_socket.bind((host_name, port))
print( "Binding successful!\n")
print("\nThis is your IP: ", s_ip, "\n")
name = input('\nEnter name: ')
new_socket.listen(1)
conn, add = new_socket.accept()
print("\nReceived connection from ", add[0])
print('\nConnection Established. Connected From: ',add[0])
client = (conn.recv(1024)).decode()
print(client + ' has connected...\n\n')
conn.send(name.encode())
def send():
message = input('\nMe : ')
conn.send(message.encode())
message = conn.recv(1024)
message = message.decode()
print(client, ':', message)
while True:
try:
send()
except:
print("there is a Problem in the script!")
time.sleep(5)
exit()