Hello,
I am attempting to write an mpd frontend. I can connect to the daemon, open the socket, close it, etc.
When I want to receive the data, I can receive the initial connection message from the daemon with GNAT.Sockets.Receive_Socket, but when I try to go with the examples on Wikibooks, or from the example in the comments of g-socket.ads with streams, nothing happens. Here is an example of what I am doing:
-- Initialize sockets
GNAT.Sockets.Initialize;
-- Create the client socket
GNAT.Sockets.Create_Socket (Socket => Client);
-- Assign address and port to server address
Address.Addr := GNAT.Sockets.Inet_Addr (Image => Server_IP);
Address.Port := Server_Port;
-- Connect socket to server
GNAT.Sockets.Connect_Socket (Socket => Client, Server => Address);
-- Receive data from server
GNAT.Sockets.Receive_Socket (Socket => Client,
Item => Data,
Last => Size);
-- Concat buffer into string
for i in 1 .. Size loop
Ada.Strings.Unbounded.Append
(Source => Response,
New_Item => Character'Val (Data (i)));
end loop;
-- Print the response
Ada.Text_IO.Put_Line (Item => Ada.Strings.Unbounded.To_String
(Source => Response));
-- Close socket
GNAT.Sockets.Close_Socket (Socket => Client);
Now this works, and I get the response expected. If I attempt the following, I get nothing:
-- ... [same code until -- Connect socket to server] ...
-- Create channel for streaming data
Channel := GNAT.Sockets.Stream (Socket => Client);
Ada.Text_IO.Put_Line (String'Input (Channel));
Why is this?
I reckon I have not understood streams, or that I am completely missing something else.
Thank you all very much in advance,
/ vjalmr