我已經發現兩種類型的基於所述IO ::插座:: INET模塊,其接收並經由IP地址發送消息上網站程序。使用IO ::插座:: INET接收和發送在消息單個提示
接收郵件程序:
use IO::Socket::INET;
my $text;
$MySocket=new IO::Socket::INET->new (LocalPort=>1234,Proto=>'udp');
while(1)
{
$MySocket->recv($text,128);
$hostip=$MySocket->peerhost();
if($text ne '')
{
print "\nReceived message from $hostip: $text \n";
print "Command Output:\n";
#system("$text");
print "\n";
}
else
{
print "Client has exited!"; exit 1;
}
}
發送消息:
use IO::Socket::INET;
#Enter Destination IP Message
print "Please Enter the destination IP: \n";
$DestinationIP = <STDIN>;
chomp $DestinationIP;
#Enter message to sent to Server
print "Please Enter your message: \n";
$MySocket=new IO::Socket::INET-> new(PeerPort=>1234,Proto=>1234,Proto=>'udp',PeerAddr=>$DestinationIP);
#$MySocket->send($msg);
while($msg=<STDIN>)
{
chomp $msg;
if($msg ne '')
{
print "\n Sending $msg";
if($MySocket->send($msg))
{
print "done \n";
print "\nPlease Enter another message:";
}
}
}
我的問題是如何處理/合併在一個單一的MS-DOS提示符下運行這些程序。
對於如:
`Receiving and sending message in Single Prompt.`
我真誠的道歉,如果我曾問過任何假設沒有意義。
所以先把話說清楚,你只是想運行在接收和在一個腳本發送?不需要運行2個程序,但只有一個? – 2016-11-25 13:15:52
@Gerry:是的。絕對是聊天。 – ssr1012
好吧,讓我迅速發佈一個答案。還有一個問題,你是否想使用收到消息中的任何值通過發送功能發送? – 2016-11-25 13:18:58