任何人都可以指引我在IO :: Socket :: INET中開發的雙向客戶端服務器腳本,發送和接收短信? 我需要研究它的流程和工作。 TY。雙向客戶端服務器
雙向客戶端服務器
回答
這裏是上述問題的最簡單的解決方案:
服務器腳本
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket::INET;
my $socket;
my $clientsocket;
my $serverdata;
my $clientdata;
$socket = new IO::Socket::INET (
LocalHost => '127.0.0.1',
LocalPort => '0155',
Proto => 'tcp',
Listen => 1,
Reuse => 1
) or die "Oops: $! \n";
print "Waiting for the Client.\n";
$clientsocket = $socket->accept();
print "Connected from : ", $clientsocket->peerhost(); # Display messages
print ", Port : ", $clientsocket->peerport(), "\n";
# Write some data to the client
$serverdata = "This is the Server speaking :)\n";
print $clientsocket "$serverdata \n";
# read the data from the client
$clientdata = <$clientsocket>;
print "Message received from Client : $clientdata\n";
$socket->close();
客戶端腳本:
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket::INET;
my $socket;
my $serverdata;
my $clientdata;
$socket = new IO::Socket::INET (
PeerHost => '127.0.0.1',
PeerPort => '0155',
Proto => 'tcp',
) or die "$!\n";
print "Connected to the Server.\n";
# read the message sent by server.
$serverdata = <$socket>;
print "Message from Server : $serverdata \n";
# Send some message to server.
$clientdata = "This is the Client speaking :)";
print $socket "$clientdata \n";
$socket->close();
這是一個甜蜜的代碼! :) TY – user2250900 2013-04-08 20:00:17
它就像任何其他文件句柄。
while (<$socket>) { # Receiving
print $socket $_; # Sending
}
我可以從客戶端發送文本到服務器,但我無法將其發送到服務器(確認)。 是否需要等待響應或任何這樣的事情在編? – user2250900 2013-04-08 12:09:45
當然你必須等待迴應。如果你的客戶沒有得到迴應而退出,它不會得到它。你需要等待,就像我展示服務器一樣。 – ikegami 2013-04-08 12:19:30
- 1. 雙向UDP客戶端和服務器?
- 2. 客戶端 - 服務器雙向通信
- 3. 跨語言雙向客戶端 - 服務器通信方法?
- 4. 如何實現一個雙向jsonrpc + twisted服務器/客戶端
- 5. Java雙向套接字連接(服務器/客戶端)
- 6. Qt雙向客戶端服務器使用QTcpSocket和QTcpServer
- 7. 跨語言客戶端/服務器的雙向RPC選項
- 8. C++ UDP雙向客戶端/服務器交付
- 9. Java:加密的服務器/客戶端雙向通信?
- 10. 雙向客戶端服務器架構/實現
- 11. 雙向Java客戶端/服務器通信
- 12. 異步雙向客戶端/服務器模型>網絡
- 13. 雙向客戶端服務器網絡通信
- 14. 顯示客戶端 - 服務器雙向通信的ActiveMQ示例?
- 15. 雙向WCF客戶端 - 服務器通信
- 16. 雙向溝通服務器/客戶端架構?
- 17. 服務器已拒絕客戶端憑據,雙工wcf服務
- 18. Java:服務器/客戶端 - >客戶端/客戶端
- 19. 客戶端服務器 - (TCP)
- 20. BufferedReader,客戶端/服務器
- 21. JXTA客戶端 - 服務器
- 22. 客戶端服務器C++
- 23. 服務器客戶端iphone
- 24. 服務器和客戶端
- 25. 服務器/客戶端C#
- 26. Android客戶端服務器
- 27. Arduino客戶端/服務器
- 28. 服務器客戶端java
- 29. Java客戶端服務器
- 30. TCP客戶端服務器
我一直想寫一個,但我有機器人能夠發展一個。我也無法找到合適的代碼。所以,如果你能告訴我一個.. – user2250900 2013-04-08 11:37:20
你沒有通過這一個... http://stackoverflow.com/questions/15844918/2-way-communication-between-server-client-scripts – 2013-04-08 11:37:41
這可以幫助,但不是雙向的,我猜測.. http://www.conceptsolutionsbc.com/perl-articles-mainmenu-41/25-modules-and-packages/54-writing-client-server-applications-using-iosocket – 2013-04-08 11:38:05