opensensorhub / osh-core

OpenSensorHub Core Modules
http://docs.opensensorhub.org
Mozilla Public License 2.0
32 stars 16 forks source link

Implement TCPServerCommProvider 2 #245

Closed MichaelElmore1 closed 4 months ago

MichaelElmore1 commented 11 months ago

I added a TCPServerCommProvider, which allows OSH to act as a server and send or receive data from a number of clients.

Since there are multiple input and output streams, one per client, I added onConnection, where you can register a listener for connections. To use it, register some code to be run when a client connects, like this:

commProvider.onConnection(args -> {
//do stuff with args.getInputStream() and getOutputStream()
})

or (alt syntax)

commProvider.onConnection(this::handleConnection)
...

handleConnection(ConnectionEventArgs args) {
//do stuff with args.getInputStream() and getOutputStream()
}

Note that this is a duplicate of https://github.com/opensensorhub/osh-core/pull/241 but with TCPCommProvider unmodified. I wanted to make it the same PR, but I made a mess of things. Sorry about that.