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(th reading.Thread) :
def __init__(self, conn):
threading.Threa d.__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(s ocket.AF_INET, socket.SOCK_STR EAM)
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(co nnexion)
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.Thre ad):
"""objet thread gerant la reception des messages"""
def __init__(self, conn):
threading.Threa d.__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.Threa d):
"""objet thread gerant l'emission des messages"""
def __init__(self, conn):
threading.Threa d.__init__(self )
self.connexion = conn # ref. du socket de connexion
def run(self):
while 1:
message_emis = raw_input()
self.connexion. send(message_em is)
# Programme principal - etablissement de la connexion :
connexion = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
try:
connexion.conne ct((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 2212
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 server works OK.
I've heard, that P2.3 has SSL support included in himself and also, I was
trying P2.2 with pyOpenSSL wrappers and extensions, but unsuccesfuly...
So, could you give me a few lines of python code which makes such things:
|
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 remove old
version (as well as the mx libraries I had installed). I then
installed the new version as a user with the Administrator role. I
know I'm technically not supposed to install to a directory with a
space in the name, but it worked fine for...
|
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 multicast traffic from the
client, so I am afraid that somewhere there might be a mistake in the
script. Would anybody care to have a quick check ? Never mind the
French comments, I ´borrowed´ the script from a French website...
// Code du serveur
|
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 computations, the only data transfered is
user mouse/kbd input.
It works synchronously, but somehow, when I play in client window,
both client and server have 17 fps, while when playing in server
window, server has 44 fps while client ...
|
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 déposé un code permettant visiblement de
passer un script en argument tout en signant son passage (rory). Je voulais
savoir quel était la meilleure façon de sécuriser ces fichiers. Comme c'est
un serveur Unix, j'ai déjà corrigé les autorisations...
| |
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 saved on the
server again (when client use save button or close Excel).
MY TESTS : I had coded that (in php) :
echo "<FORM METHOD=post TARGET=_blank> ";
|
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 server code and the J2ME client code, so that I can make my application with your help.
Thanks
Best regards, MELE Eliseo (eliseo@dplanet.ch)
|
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.
l'interface QT contient 2 champs Edittext(recep , emmision) l'un est réservé aux messages emis par le client et l'autre pour les messages renvoyés par le serveur; et un bouton connexion(conec).
le probléme, c'est qu'il y a eu une "petite" connexion...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |