Bonjour,

J'ai créé un client et un serveur; le client se connecte bien au serveur et lui envoie bien les données, mais maintenant j'aimerais que le serveur envoie lui aussi des données au client et quand j'essaie de faire ça, j'ai l'erreur suivante : "channel "sock4" wasn't opened for writing"

Quelqu'un peut-il m'aider ??

Je donne le code au cas où...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
 
#!/usr/local/bin/wish
 
# ###############
#
# server side
#
# ###############
 
variable channel
 
#----------------------------------------
# client connection
#----------------------------------------
proc server {channel host port} \
{
	# save client info
    set ::($channel:host) $host
    set ::($channel:port) $port
    # log
    log "<opened>\n"
    set rc [catch \
    {
    	# set call back on reading
      	fileevent $channel readable [list input $channel]
    } msg]
    if {$rc == 1} \
    {
      	# i/o error -> log
      	log server ***$msg
    }
}
#----------------------------------------
 
 
#----------------------------------------
# client e/s
#----------------------------------------
proc input {channel} \
{
	if {[eof $channel]} \
    {
    	# client closed -> log & close
      	log $channel <closed>
     	catch { close $channel }
    } \
    else \
    {
      	# receiving
      	set rc [catch { set count [gets $channel data] } msg]
      	if {$rc == 1} \
      	{
        	# i/o error -> log & close
        	log ***$msg
        	catch { close $channel }
      	} \
      	elseif {$count == -1} \
      	{
        	# client closed -> log & close
        	log <closed>
        	catch { close $channel }
      	} \
      	else \
      	{
        	# got data -> do some thing
        	log $data
      	}
    }
}
#----------------------------------------
 
#----------------------------------------
# sending data on the socket
#----------------------------------------
proc output {channel data} \
{
	set rc [catch \
    {
    	puts $channel "$data"
      	flush $channel
    } msg]
    if {$rc == 1} { log $msg }
}
#----------------------------------------
 
#----------------------------------------
# Send command to the client
#----------------------------------------
proc sendCommand {} \
{ 
	variable channel
 
	if {[eof $channel]} \
    {
    	# client closed -> log & close
      	log $channel <closed>
     	catch { close $channel }
    } \
    else \
    {
    	set command [.fra1.frarec.txt1scrb.txtrec get 1.0 end]
		puts $command
		output $channel $command
	}
}
#----------------------------------------
 
#----------------------------------------
# log
#----------------------------------------
proc log {msg} \
{ 
	puts -nonewline "$msg" 
	.fra1.frarec.txt1scrb.txtrec insert 200.0 $msg
	.fra1.frarec.txt1scrb.txtrec see end
}
#----------------------------------------
 
 
# ===================
# start
# ===================
#----------------------------------------
# open socket
#----------------------------------------
catch { console show }
catch { wm protocol . WM_DELETE_WINDOW exit }
set port 6000 ;# 0 if no known free port
set rc [catch \
{
	set channel [socket -server server $port]
    if {$port == 0} \
    {
    	set port [lindex [fconfigure $channel -sockname] end]
      	puts "--> server port: $port"
    }
} msg]
if {$rc == 1} \
{
	log "<exiting>\n***$msg"
    exit
}
set (server:host) server
set (server:port) $port
 
 
 
 
 
#----------------------------------------
#frame principale
frame .framain -relief flat -bd 1 -height 800 -width 800
pack configure .framain
#----------------------------------------
#frame secondaire fra1
frame .fra1 -relief flat -borderwidth 1
#----------------------------------------
#frame reception avec bouton et texte avec scroll bar
frame .fra1.frarec -relief flat -borderwidth 1
frame .fra1.frarec.txt1scrb -bg white
text .fra1.frarec.txt1scrb.txtrec -width 97 -height 52 -fg #000000 -bg #ffffff -font "Tahoma 10 normal" -yscrollcommand " .fra1.frarec.txt1scrb.scrbrec set "
scrollbar .fra1.frarec.txt1scrb.scrbrec -command " .fra1.frarec.txt1scrb.txtrec yview "
pack configure .fra1.frarec.txt1scrb.scrbrec -side right -fill y
pack configure .fra1.frarec.txt1scrb.txtrec -side left
pack configure .fra1.frarec.txt1scrb -side top -expand 0 -fill none 
bind .fra1.frarec.txt1scrb.txtrec <KeyPress-Return> {sendCommand}
#----------------------------------------
#compilation fenetres
pack configure .fra1.frarec -side top -expand 0 -fill none 
place configure .fra1 -x 0 -y 0
#---------------------------------------
 
# ===================

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
 
#!/usr/local/bin/wish
 
# ######################################## #
# ######################################## #
# #######     client side       ########## #
# ######################################## #
# ######################################## #
 
 
 
#########################################
#            Serial                     #
#########################################
#----------------------------------------
# Configure and open the serial port
#----------------------------------------
proc openSerial { } {
	set serialPort [open /dev/ttyUSB0]
	fconfigure $serialPort -mode "115200,n,8,1"
	fconfigure $serialPort -blocking 0 -buffering none
	return $serialPort
}
#----------------------------------------
 
 
#########################################
#            Socket                     #
#########################################
#----------------------------------------
# sending data on the socket
#----------------------------------------
proc send:data {channel data} \
{
	set rc [catch \
    {
    	puts $channel "$data"
      	flush $channel
    } msg]
    if {$rc == 1} { log $msg }
}
#----------------------------------------
 
#----------------------------------------
# close the socket
#----------------------------------------
proc close:exit {channel} \
{
	close $channel
    exit
}
#----------------------------------------
 
#----------------------------------------
# log
#----------------------------------------
proc log {msg} { puts "$::host:$::port: ***$msg" }
#----------------------------------------
 
 
# ===================
# start
# ===================
 
#----------------------------------------
# open socket
#----------------------------------------
set host localhost
set port 6000
set rc [catch { set channel [socket $host $port] } msg]
if {$rc == 1} { log $msg; exit }
 
#----------------------------------------
# open serial
#----------------------------------------
set serialPort [openSerial]
 
#----------------------------------------
# get data from serial port and 
# send it on the socket
#----------------------------------------
while {1} \
{
	set data [read $serialPort 1]
	set byteSize [string bytelength $data]
	if { $byteSize == 1 } {
		send:data $channel $data
		puts -nonewline "$data"
	} 
}
 
#----------------------------------------
# enter event loop
#----------------------------------------
# vwait forever
# ===================
Merci