0
package require itcl
package require json
package require ncgi
namespace import ::itcl::*
class StaffClientWithManhattan {
variable clientSocket
constructor {port} {
set host localhost
set clientSocket [socket $host $port]
fconfigure $clientSocket -buffering full -buffersize 4096
}
method send_message {message} {
set jsonMessage [json::dict2json $message]
set stringMessage [format "%s" $jsonMessage]
puts "request is: $stringMessage"
puts $clientSocket $stringMessage
flush $clientSocket
set replyFromServer [ncgi::decode [gets $clientSocket]]
puts " Response from server : $replyFromServer"
set resultInDict [json::json2dict $replyFromServer]
puts "from server in dict format: $resultInDict"
close $clientSocket
return $resultInDict
}
method create_component {varrequest_type varcommand varcomponent_type vardriver_path varrequest_timeout varhost varport} {
set message [dict create request_type $varrequest_type command $varcommand params [dict create component_type $varcomponent_type driver_path $vardriver_path request_timeout $varrequest_timeout host $varhost port $varport]]
puts "request in dictionary format: $message"
set response [send_message $message]
set component_id [dict get $response component_id]
return $component_id
}
method perform_action {varrequest_type varcommand varcomponent_id} {
set message [dict create request_type $varrequest_type command $varcommand params [dict create component_id $varcomponent_id]]
puts "Action message is: $message"
set response [send_message $message]
return $response
}
}
StaffClientWithManhattan scm 9999
set component_id "[scm create_component action create_component ManhattanClient C://NodeWebKit//chromedriver2_server.exe 5 localhost 9999]"
#StaffClientWithManhattan scm 9999
#scm perform_action action find_people 1
響應在這個程序中,我嘗試連接到一個Python服務器,服務器被正確接收請求和發送響應,但我的TCL客戶端不接收響應。請幫助我,我嘗試了很多,但無法理解問題所在。TCL客戶端沒有收到來自蟒蛇服務器
謝謝唐納您的回覆 – user3814843
謝謝唐納你的回覆:你的猜測是正確的,它是行設置replyFromServer [ncgi :: decode [gets $ clientSocket]]它正在撫摸。控制永遠不會到達這條線。我已經嘗試過 - 翻譯,但它仍然無法正常工作。 – user3814843
還有一件事,先生,當我調試代碼時,它終止於該行:set response [send_message $ message]通過生成錯誤消息,如下所示:執行錯誤206:ItclObjectCmd無法獲得上下文對象(NULL) 執行時 「send_message $消息」 堆棧跟蹤: \t#0文件:/ d:/Uttam/eclpro/server-client/staffing/StaffClientWithManhattan.itcl [34] \t#1的文件:/ d:/烏塔姆/ eclpro /服務器 - 客戶/人員/ StaffClientWithManhattan.itcl [48] – user3814843