I've tried a mix of combinations using the new line character but the output is still an empty string.
message = input(" -> ") # take input
client_socket.send("\n".encode())
client_socket.send(("\n" + message).encode()) client_socket.send("\n".encode())
Hello, I was testing sockets in tcl and I got a tcl server and tcl client to communicate correctly.
I thought I would try using a python client to send data to my tcl server.
The python client will send data but the tcl server will output it as a empty string when I get it from the channel.
I was wondering if this was the tcl servers fault or the python clients fault?
client_socket.send(message.encode()) # send message
Unfortunately the argument has to be in bytes.
I changed the tcl server receive function to do 3 outputs to match the inputs given by the python client but none of them had the input message from the client as they were all empty strings.
fconfigure $chan -blocking 0 -buffering line
server:
proc accept {chan addr port} {
fconfigure $chan -blocking 0 -buffering line
fileevent $chan readable [list receive $chan]
puts "$addr joined"
}
proc receive {channel} {
puts [chan gets $channel]
close $channel
}
Unfortunately the argument has to be in bytes.
I changed the tcl server receive function to do 3 outputs to match
the inputs given by the python client but none of them had the input
message from the client as they were all empty strings.
proc receive {channel} {
puts [chan gets $channel]
flush $channel
puts [chan gets $channel]
flush $channel
puts [chan gets $channel]
flush $channel
close $channel
}
hello
hello again
I got it to work as it closes the socket connection but the receive
function continues to run causing an error as the channel no longer
exists.
python input:
hello
hello again
tcl output:
87.115.149.231 joined
Got: hello
Got: hello again
Got:
Client has disconnected.
can not find channel named "sock5573b3ce5050"
while executing
"read $channel"
(procedure "receive" line 8)
invoked from within
"receive sock5573b3ce5050"
receive function:
proc receive {channel} {
if {[eof $channel]} {
close $channel
puts "Client has disconnected."
}
puts "Got: [read $channel]"
flush $channel
}
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 07:51:43 |
| Calls: | 12,100 |
| Files: | 15,003 |
| Messages: | 6,517,941 |