Bonjour,
je suis bloqué ilya preque 2 semaines dans le code suivant. je veut que le client et le serveur envoyent leurs message d'une maniere comme msn. je crois qu'ilya quelque chose à ajouter dans les boucles. d'abord code serveur:
from socket import *
import socket, sys, threading
class ThreadClient(threading.Thread):
def __init__(self, conn):
threading.Thread.__init__(self)
self.connexion = conn
def run(self):
nom = self.getName()
while 1:
msgServeur = raw_input("S> ")
connexion.send(msgServeur)
msgClient = self.connexion.recv(1024)
if msgClient.upper() == "FIN" or msgClient =="":
break
message = "%s> %s" % (nom, msgClient)
print message
for cle in conn_client:
if cle != nom:
conn_client[cle].send(message)
self.connexion.close()
del conn_client[nom]
print "Client %s deconnecte." % nom
mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
mySocket.bind(('127.0.0.1', 84))
except socket.error:
print "La liaison du socket a l'adresse choisie a echoue."
sys.exit()
print "Stand by!!!!"
mySocket.listen(5)
conn_client = {}
while 1:
connexion, adresse = mySocket.accept()
th = ThreadClient(connexion)
th.start()
it = th.getName()
conn_client[it] = connexion
print "Client %s connecte, adresse IP %s, port %s." %\
(it, adresse[0], adresse[1])
connexion.send("Vous etes connecte. Envoyez vos messages.") code client.
# Definition d"un client reseau gerant en parallele l'emission
# et la reception des messages (utilisation de 2 THREADS).
host = '127.0.0.1'
port = 84
import socket, sys, threading
class ThreadReception(threading.Thread):
"""objet thread gerant la reception des messages"""
def __init__(self, conn):
threading.Thread.__init__(self)
self.connexion = conn # ref. du socket de connexion
def run(self):
while 1:
message_recu = self.connexion.recv(1024)
print "*" + message_recu + "*"
print "Client arrete. Connexion interrompue."
self.connexion.close()
class ThreadEmission(threading.Thread):
"""objet thread gerant l'emission des messages"""
def __init__(self, conn):
threading.Thread.__init__(self)
self.connexion = conn # ref. du socket de connexion
def run(self):
while 1:
message_emis = raw_input()
self.connexion.send(message_emis)
# Programme principal - etablissement de la connexion :
connexion = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
connexion.connect((host, port))
except socket.error:
print "La connexion a echoue."
sys.exit()
print "Connexion etablie avec le serveur."
# Dialogue avec le serveur : on lance deux threads pour gerer
# independamment l'emission et la reception des messages :
th_E = ThreadEmission(connexion)
th_R = ThreadReception(connexion)
th_E.start()
th_R.start()
1 2196
C'est possible de mettre le code dans tag?
For those that don't speak french:
Hey,
I'm stuck, almost 2 weeks. I want the client and server to send message kinda like msn does it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Krzysztof Pa¼ |
last post by:
Hi,
I want to make simple client in phyton, which would be able to communicate
with Java server using SSL sockets.
There is the Java clients, which is doing this - so I'm pretty sure, that
Java...
|
by: Justin Stockton |
last post by:
I recently upgraded from ActivePython 2.2.2 to ActivePython 2.3.2 and
I'm running into an issue importing the win32com.client module.
Before installing the new version, I made sure to properly...
|
by: nazgulero |
last post by:
Hello all,
I am fairly new to C++, and I am trying to write a client/server API
for multicast. I have come across the script below, but for some
reason, the server does not get any of the...
|
by: Michael Rybak |
last post by:
hi, everyone.
I'm writing a 2-players game that should support network mode. I'm now
testing it on 1 PC since I don't have 2. I directly use sockets, and
both client and server do...
|
by: Chris |
last post by:
Bonjour,
Plusieurs fichiers PHP d'un programme open source de compteur de visites
viennent de se faire hacker sur mon serveur (hébergement mutualisé chez un
fournisseur d'accès). Le hacker a...
|
by: Djim |
last post by:
Hello,
i am starting PHP, and after 2 days of search, i am posting.
MY PURPOSE : opening a XLS files (in MS Excel) on the client side, the
user can update anything, then it will be automaticly...
|
by: eliseo |
last post by:
Hello,
I want to make the same application : python Serveur and J2me Client whit ssl socket.
I would like to know if you have solved the problem?
Can you show me the final version of python...
|
by: 7stud |
last post by:
My question pertains to this example:
#!/usr/bin/env python
import socket, sys, time
host = sys.argv
textport = sys.argv
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
by: tsic |
last post by:
Bonjour,
Voilà, j'ai débuté recemment avec python et je veux faire une connexion client serveur (windows) par l'intermédiaire d'une interface QT Designer v 4. j'ai choisi ERIC v 4 comme IDE.
...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |