我已经发现两种类型的基于所述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