From: Stephen S. <rad...@gm...> - 2020-08-04 16:16:14
|
Hi Roland, On Tue, Aug 4, 2020 at 1:36 PM Aigner Roland <rol...@fh...> wrote: > However I struggle to figure out how I would connect a client to this > server, i.e. what the code should look like for a client receiving the data > sent by this server. > I'm not sure if your concept of client and server is mixed up here? In OSC it is the client sending data to the server. Documentation and sample code leave me scratching my head, I tried to > figure out by checking the library source code, but so far I failed to > understand. From the fact that lo_send_message_from requires a target > address I infer that I would have to iterate through all connected clients > and sent to the respective sockets manually. > You can get a target address by creating one, if you know the destination, or you can get the sender's address from inside a message handler: lo_address a = lo_message_get_source(data); lo_send(a, "/hi", "i", 3); > But how do I know when a client connection gets accepted? > Who knows? The server knows because a handler is being executed. The client only knows whether the send failed. > So, summarizing, my two remaining questions are > > 1. how do I connect a client to the server? > > Your code (which I snipped from the message, apologies) is correct. You just create a server and specify LO_TCP for its protocol, and a client specifying LO_TCP for its protocol. Then the client should be able to make a connection to the server and send it a message. > > > 1. how do I know what clients are currently connected that I would > have to send my packages to? > > Hm, I don't think liblo provides a way to enumerate the current client connections.. could be interesting, but it's not too usual to want to broadcast to a random client. Usually messages from the server are limited to _responses_ that are sent during message handlers, and in that case you can get the response destination using lo_message_get_source as I outlined above. Note that if your *client* wants to receive a response... actually it cannot, it needs to set up a *server* to receive the response, and use lo_send_from, specifying that server. That's how the destination server can find where to send responses back to. So for bidirectional messaging, each side has a server. If you need to broadcast a message to multiple servers, you can look into multicast or broadcast messaging, but that's for UDP. As for sending a message to all currently connected clients, I'm not sure.. I'll have to think on how to do that and whether it's a good idea. Theoretically it is possible. Keep in mind that OSC is typically a UDP protocol and is designed around one-way messaging. Liblo incidentally supports responses, but it's common for UDP protocols to be unidirectional. On the TCP side, often clients will make a connection, send a message, *maybe* wait for a response, and then close the connection. Long-lived connections are more rarely used; but if they are, they shouldn't *depend* on the connection state. Hope this helps, Steve |