From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,99ad16995c7745f2,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!f63g2000hsf.googlegroups.com!not-for-mail From: "snoopysalive@googlemail.com" Newsgroups: comp.lang.ada Subject: How to implement a server socket compatible to telnet? Date: Fri, 8 Aug 2008 04:31:36 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 88.217.51.94 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1218195097 14975 127.0.0.1 (8 Aug 2008 11:31:37 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 8 Aug 2008 11:31:37 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f63g2000hsf.googlegroups.com; posting-host=88.217.51.94; posting-account=b7G67QoAAABjwLRYV73fYo_8iKCvB0IZ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071719 Firefox/3.0.1,gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 fw-pasing:800 (squid/2.6.STABLE17) Xref: g2news1.google.com comp.lang.ada:1537 Date: 2008-08-08T04:31:36-07:00 List-Id: Hello! For some reasons I had to implement a server socket in C++. Now I want to do the same in Ada and so I read the GNAT.Sockets-library and implemented a shorter version of the example given in the g- socket.ads. The problem is that I want to implement the server in a kind, that processes written in other languages like the tool telnet or a Java- programme are able to communicate with it. But my server isn't able to print a message sent by the telnet-client, so I think that I've written something wrong in my code. Here's the code: with Ada.Text_IO, Ada.Exceptions, GNAT.Sockets; use Ada.Text_IO, Ada.Exceptions, GNAT.Sockets; procedure Server is Host : String := "localhost"; Port : Port_Type := 7777; Address : Sock_Addr_Type; Server : Socket_Type; Client : Socket_Type; Channel : Stream_Access; begin -- Server Initialize; Address.Addr := Addresses (Get_Host_By_Name (Host), 1); Address.Port := Port; begin Create_Socket (Server); Put_Line ("Server socket created"); exception when E : Socket_Error => Put_Line (Standard_Error, "Create_Socket failed"); end; -- Create server socket begin Set_Socket_Option (Server, Socket_Level, (Reuse_Address, True)); Put_Line ("Socket address reused"); exception when E : Socket_Error => Put_Line (Standard_Error, "Set_Socket_Option failed"); end; -- Resuse socket address begin Bind_Socket (Server, Address); Put_Line ("Server socket bound"); exception when E : Socket_Error => Put_Line (Standard_Error, "Bind_Socket failed"); end; -- Bind server begin Listen_Socket (Server); Put ("Server is listening... "); exception when E : Socket_Error => Put_Line (Standard_Error, "Listen_Socket failed"); end; -- Listening... begin Accept_Socket (Server, Client, Address); Put_Line ("Got client connection"); delay 0.2; Channel := Stream (Client); Put_Line ("Client streamed"); declare Message : String := String'input (Channel); begin Put_Line (Message); end; -- Get client message and print it to the screen exception when E : Socket_Error => Put_Line (Standard_Error, "Accept_Socket failed"); end; -- Client handling begin Close_Socket (Client); Put_Line ("Client closed"); Close_Socket (Server); Put_Line ("Server closed"); exception when E : Socket_Error => Put_Line (Standard_Error, "Close_Socket failed"); end; -- Close client and server sockets Finalize; end Server; The server's output is: "Server socket created Socket address reused Server socket bound Server is listening... Got client connection Client streamed Client closed Server closed" The empty line should be the message sent by telnet, but like you can see, the message is empty. So, can anybody explain to me, what I have done wrong? Thank you, Matthias