All pastes #568115 Raw Edit

Untitled

public text v1 · immutable
·published 2007-06-15 08:40 UTC
rendered paste body
import threading
import random
import time
import socket
import pickle
import copy

HOST = '127.0.0.1'
PORT = 5313

class ThreadClient(threading.Thread):

    def __init__(self, conn):
        
        threading.Thread.__init__(self)
        
        self.connexion = conn
        msgClient = self.connexion.recv(1024) #ca marche
        self.connexion.send('slkej') #ca ne marche pas
        return
                    
mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
    mySocket.bind((HOST, PORT))
except socket.error:
    print "La liaison du socket à l'adresse choisie a échoué."
    sys.exit()
print "Serveur prêt, en attente de requêtes ..."
mySocket.listen(5)

conn_client = []

while 1:
    connexion, adresse = mySocket.accept()
    connexion.send('blabla') # ici ca marche
    th = ThreadClient(connexion)
    th.start()
    it = th.getName()        # identifiant du thread
    conn_client.append(th)
    print "Client %s connecté, adresse IP %s, port %s." % (it, adresse[0], adresse[1])