AdaSockets是一个Ada95的socket编程开发包,支持单播和多播套接字,使用面向对象结构来简化套接字操作。
示例代码:
withAda.Command_Line;useAda.Command_Line;withAda.Exceptions;useAda.Exceptions;withAda.Text_IO;useAda.Text_IO;withSockets.Stream_IO;useSockets,Sockets.Stream_IO;procedureStream_Senderis--Usage:stream_senderremotehostremoteport--Example:stream_senderlocalhost5000Outgoing_Socket:Socket_FD;Stream:aliasedSocket_Stream_Type;Line:String(1..200);Last:Natural;beginifArgument_Count/=2thenRaise_Exception(Constraint_Error'Identity,"Usage:"&Command_Name&"remotehostremoteport");endif;Socket(Outgoing_Socket,PF_INET,SOCK_STREAM);Connect(Outgoing_Socket,Argument(1),Positive'Value(Argument(2)));Initialize(Stream,Outgoing_Socket);loopPut("Typeastring>");Flush;Get_Line(Line,Last);String'Output(Stream'Access,Line(Line'First..Last));endloop;exceptionwhenEnd_Error=>null;endStream_Sender;
评论