Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

thread usage for a socket application: can not find channel named "sock9"

Status
Not open for further replies.

Leaffy

Programmer
Aug 20, 2012
1
0
0
CH
Hello,

I've got some problem with my application which uses thread when I try to treat each client need on server side. Dans I try to create one thread per client, and that's why I have chosen to create a list to add each client connected to the server(on ClientData list), but I have a problem when I want to pass the client channelin the thread even if I include it in the procedure by parameter reference.
function client_attempt:
proc client_attempt {ClientData} {
for {set client 0} {$client < [llength $ClientData]} {incr client} {
set clientInfo [lindex $ClientData $client]

#we get each client info: adress, port number and channel to initialize the connection
set clientChan [lindex $clientInfo 0]
set clientAddr [lindex $clientInfo 1]
set clientPort [lindex $clientInfo 2]

#puts "donnees client: $clientInfo" ;#get each client connected
puts "channel client: $clientChan"
puts "adresse client: $clientAddr"
puts "port client: $clientPort"

_clientConnect $clientChan $clientAddr $clientPort
}
}
fonction _clientConnect:
proc _clientConnect {clientChan clientAddr clientPort} {
after 0 [list clientConnect $clientChan $clientAddr $clientPort]
}

fonction clientConnect:
proc clientConnect {clientChan clientAddr clientPort} {
####### THREAD CREATION #######
set client_thread [thread::create -joinable {
proc clientConnection {clientChan clientAddr clientPort} {
puts $clientChan "Bonjour $clientAddr on $clientPort!"
close $clientChan
}
thread::wait
}]
thread::transfer $client_thread $clientChan

thread::send $client_thread [list clientConnection $clientChan $clientAddr $clientPort] ;#rajouter async quand tout marchera
thread::release -wait $client_thread
puts "Envoi bonjour termine"
}

main function (callback socket server):
proc transfer_initialisation {channel client_address client_port} {
#don't block clients
fconfigure $channel -blocking 0 -buffering line

#variables to store each client
variable clientData
variable list_clients

variable client_count

lappend clientData [list $channel $client_address $client_port]

if { [llength list_clients] > 0} { ;#if we have more than one user, we regenerate the list to count the previous client once, else the list contains the same client many times...
set list_clients

  • lappend list_clients [list $clientData]
    } else {
    lappend list_clients [list $clientData]
    }
    puts "challenge accepted, client added\n"
    client_attempt $clientData

    incr client_count ;#we count each client connected
    }

    socket creation:
    set opened_port [catch {set dl [socket -server transfer_initialisation $transfer_port]} stderr][/code]Le premier thread est bien crée mais lors de la connexion du deuxième client, j'obtiens l'erreur suivante:
    Code:
    can not find channel named "sock9"
        while executing
    "thread::transfer $client_thread $clientChan"
    
    Does anybody have any idea?
 
I can't really follow what's going on but shortly before the statement throwing the error (thread::transfer $client_thread $clientChan), it appears that you close the connection:
Code:
close $clientChan
Could that be the problem?

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top