Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- #ask user if it is a client or server
- clientORserver=input('Do you want a client or a sever (C/S) ')
- cORs=clientORserver.upper()
- if cORs == 'C':
- connection_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s_address=input('server\'s address ->')
- connection_socket.connect((s_address,8081))
- yrname=input('What is your name-> ')
- connection_socket.send(bytes(yrname+ 'is connected to the server' , 'utf-8'))
- elif cORs =='S':
- server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- server_socket.bind(("0.0.0.0",8081))
- server_socket.listen()
- print("waiting for connection")
- connection_socket, address = server_socket.accept()
- print("Client connected")
- else: print('Error')
- while True:
- message=connection_socket.recv(1024)
- print(message.decode())
- new_message=input('Next message -> ')
- connection_socket.send(new_message.encode())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement