我正在使用Ada进行UDP通信。该代码必须将一些数据发送给另一个将要处理它的主机。我试图发送初始消息来开始通信,但它不起作用。我的客户代码如下:如何在Ada中创建UDP客户端
with GNAT.Sockets;
use GNAT.Sockets;
with Ada.Text_IO;
with Ada.Exceptions;
use Ada.Exceptions;
procedure Client_Send is
task Send is
entry Start;
entry Stop;
end Send;
task body Send is
Address : Sock_Addr_Type;
Socket : Socket_Type;
Channel : Stream_Access;
begin
accept Start;
-- See comments in Ping section for the first steps.
Address.Addr := Inet_Addr("192.168.0.1");
Address.Port := 7777;
Create_Socket (Socket,Family_Inet,Socket_Datagram);
Bind_Socket (Socket, Address);
Channel := Stream (Socket);
String'Output (Channel, "Hello world");
Free(Channel);
Ada.Text_IO.Put_Line ("Mesnaje Enviado");
Close_Socket (Socket);
accept Stop;
exception when E : others =>
Ada.Text_IO.Put_Line
(Exception_Name (E) & ": " & Exception_Message (E));
end Send;
begin
Initialize (Process_Blocking_IO => False);
Send.Start;
Send.Stop;
Finalize;
end Client_Send;
我正在使用Wireshark查看入站流量,但它没有收到任何东西。
展开“不起作用”。我不明白“使用Wireshark获取套接字”。 –
我使用Wireshark捕获我的网络正在接收的所有数据包。由于我在执行客户端时没有收到任何内容,因此我认为它没有正确发送。 –