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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e8c6974546bc3f7f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.248.34 with SMTP id yj2mr2262787pbc.2.1353781552268; Sat, 24 Nov 2012 10:25:52 -0800 (PST) Path: s9ni9345pbb.0!nntp.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.internetamerica!news.posted.internetamerica.POSTED!not-for-mail NNTP-Posting-Date: Sat, 24 Nov 2012 12:25:51 -0600 From: Robert Love Newsgroups: comp.lang.ada Date: Sat, 24 Nov 2012 12:27:04 -0600 Message-ID: <2012112412270484092-rblove@airmailnet> References: <2012112311175432190-rblove@airmailnet> <2012112315585358568-rblove@airmailnet> <17vopoh3g5mg4.jv11ioybge4k$.dlg@40tude.net> MIME-Version: 1.0 Subject: Re: Sockets Example Sought User-Agent: Unison/2.1.9 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 98.194.39.33 X-Trace: sv3-HPAq9+sJlPlOOoqjZgRHAXCmvYSM3UkDzM12CWz5oBEsNI45kmHYGfPpub0qgXfnoaCtlCLo2XneR+o!Zx1kMZ33GT/A0sF5Z0WLdhOkY3woVa3t5I0z2fOdYcmzDyFXbQulJCEtgd74Oy2UI+b49mVmjkEe!Pg== X-Complaints-To: abuse@airmail.net X-DMCA-Complaints-To: abuse@airmail.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3853 X-Received-Bytes: 3994 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit Date: 2012-11-24T12:27:04-06:00 List-Id: The statements about disposing of Data, what does Shutdown_Socket it do? It seems to end my task and never reach the following Close_Socket statement. If I leave it out, I see Close_Socket execute and the program seems to run fine. On 2012-11-23 22:40:59 +0000, Dmitry A. Kazakov said: > On Fri, 23 Nov 2012 15:58:53 -0600, Robert Love wrote: > >> On 2012-11-23 18:32:52 +0000, Simon Wright said: >> >>> Robert Love writes: >>> >>>> Does anyone have an example of a multi-client server in Ada they care >>>> to share? It should use the Gnat.Sockets package. I've seen samples >>>> but they don't seem complete, or at least my understanding isn't >>>> complete. >>>> >>>> Thanks in advance. >>> >>> task body Server in http://goo.gl/bXVw7 ? (lines 59 .. 143) >> >> What happens at line 120, the else clause on if Server = Socket_Server? >> Is that where data is read in on the socket? > > Socket-select might be a bit difficult to start with. Unless you expect > hundreds of simultaneous connections, there is a much simpler pattern that > uses 1-2 tasks (half- or full-duplex I/O) per connection with so-called > blocking sockets: > > Client : Sock_Addr_Type; > Server : Sock_Addr_Type; > Socket : Socket_Type; > Data : Socket_Type; > begin > Server.Addr := ...; > Server.Port := ...; > Create_Socket (Socket); > Bind_Socket (Socket, Server); > Listen_Socket (Socket); > loop > Accept_Socket (Socket, Data, Client); > -- Start an I/O task, give it Data to communicate over. > -- Client holds the address of the client. The task will > -- dispose the socket Data calling Shutdown_Socket and > -- then Close_Socket on it, when communication is over > end loop; > >> I assume the client opens the socket and the server detects it, then at >> various times the client makes data requests by sending string data. > > That happens later on when the client connects its socket. A client does: > > Create_Socket > Bind_Socket -- Client address > Connect_Socket -- Server address > -- I/O > Shutdown_Socket > Close_Socket > > The server listening to a socket gets a new socket when its calls to > Accept_Socket. Accept waits for a client to come. This happens per each > connection, i.e. for each client connection there is one accept completed > on the server side. After accept returned a socket, this socket and the > client's socket are connected, so that when one side writes something into > its socket another side reads that from the socket of its own.