-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
32 lines (24 loc) · 1.06 KB
/
Copy pathserver.py
File metadata and controls
32 lines (24 loc) · 1.06 KB
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
import socket
import unittest
def function_server():
"""création d'une conversation entre le client et le serveur"""
myIP="127.0.0.1" #IP local ou IP server si distant
myPort=63000
buffer_size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Créé un objet socket
s.bind((myIP, myPort)) # Initialisation socket
s.listen(3) # Ecoute une connexion
(cl, adress) = s.accept() # Récupere coordonée client et attibution variable
rep = ''
pseudo = input('Pseudo ?')
while rep != 'Bye':
"""tant que la réponse du client n'est pas 'Bye', continuer la conversation"""
msg = cl.recv(buffer_size) # Récupere le message encodé
msg = msg.decode()
print(" : '{}'".format(msg))
rep = input(pseudo + ' : ')
donnee = pseudo + ': ' + rep
cl.send(donnee.encode())
if __name__ == "__main__":
"""appel de la fonction function_server"""
function_server()