INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)
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 [list]
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?

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

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close