Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...On your site I feel quite confident that the contacts and feedback will make my life a little less hectic..."

Geography

Where in the world do Tek-Tips members come from?

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

Leaffy (Programmer)
20 Aug 12 10:04
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?
Bong (Programmer)
21 Aug 12 9:06
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

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!

Back To Forum

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