forked from anandalisha/Awesome_Python_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathword_transfer_client.py
33 lines (32 loc) · 1.03 KB
/
word_transfer_client.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
import socket
def create_socket():
try:
global host
global port
global s
host = "192.168.29.185" # ip of the server
port = 3603 # socket selected for transfer of information
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error as msg:
print("Socket Creation Error:" + str(msg))
def socket_connect():
global host
global port
global s
s.connect((host,port)) # to connect with the server
def send_receive(): # to input a word and send it to the server for checking
word = input("Enter a word:")
s.send(bytes(word, "utf-8")) # to send the word in form of bytes after encoding it
complete_msg = ""
while True: # to receive the message sent back from the server
msg = s.recv(8)
if len(msg) <= 0:
break
complete_msg += msg.decode("utf-8")
print(complete_msg)
def main():
create_socket()
socket_connect()
send_receive()
if __name__ == '__main__':
main()