AdaSockets 是一个 Ada 95 的 socket 编程开发包,支持单播和多播套接字,使用面向对象结构来简化套接字操作。
示例代码:
with Ada.Command_Line; use Ada.Command_Line; with Ada.Exceptions; use Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; with Sockets.Stream_IO; use Sockets, Sockets.Stream_IO; procedure Stream_Sender is -- Usage: stream_sender remotehost remoteport -- Example: stream_sender localhost 5000 Outgoing_Socket : Socket_FD; Stream : aliased Socket_Stream_Type; Line : String (1 .. 200); Last : Natural; begin if Argument_Count /= 2 then Raise_Exception (Constraint_Error'Identity, "Usage: " & Command_Name & " remotehost remoteport"); end if; Socket (Outgoing_Socket, PF_INET, SOCK_STREAM); Connect (Outgoing_Socket, Argument (1), Positive'Value (Argument (2))); Initialize (Stream, Outgoing_Socket); loop Put ("Type a string> "); Flush; Get_Line (Line, Last); String'Output (Stream'Access, Line (Line'First .. Last)); end loop; exception when End_Error => null; end Stream_Sender;