我有一个客户端-服务器 Perl 程序。我想将存储在数组中的消息发送到服务器。
服务器代码:
use IO::Socket::INET;
# Creating a a new socket
$socket=new IO::Socket::INET->new(LocalPort=>5000,Proto=>'udp');
print "\nUDPServer Waiting for client on port 5000";
while(1)
{
$socket->recv($recieved_data,1024);
$peer_address = $socket->peerhost();
$peer_port = $socket->peerport();
print "\n($peer_address , $peer_port) said : $recieved_data";
}
Run Code Online (Sandbox Code Playgroud)
客户端代码::
use IO::Socket::INET;
# Create a new socket
$socket=new IO::Socket::INET->new(PeerAddr=>'127.0.0.1',PeerPort=>5000,Proto=>'udp');
@message_array = ("message", 120, "sample");
$socket->send(@message_array);
Run Code Online (Sandbox Code Playgroud)
在服务器端我改变了,
$socket->recv(@recieved_data,1024);
Run Code Online (Sandbox Code Playgroud)
但我收到这样的错误,
UDPServer Waiting for client on port 5000usage: $sock->recv(BUF, LEN [, FLAGS]) at udp_server.pl line 17
Run Code Online (Sandbox Code Playgroud)
如何发送数组并将其打印或显示在服务器端。?