rabbits sharing a plant

Sharing socket between goroutines

2 - Request / response with channels

In Part 2 of the series, i’m going to use channels to manage a request / response on a raw, shared TCP socket. If we assume that the interaction between the service and the client is always a simple request / response on the socket (see Part 1 for the use case), then: The client send a request (command or polling for data). Then it wait for the response in the socket, reading from socket buffer until the message frame is completed....

March 25, 2023
rabbits sharing a plant

Sharing socket between goroutines

1 - Use case and naif solution

Sometimes, in low-level devices (like sensors, controllers, serial to ethernet converters, etc) the only way to interact with the hardware is via a custom protocol on top of a raw TCP socket. TCP is stream oriented so it is up to the procotol to define the way to frame the messages. In most cases 3 kind of pattern are used: Using the first byte or n bytes to specify message length, so the receiver knows when the message is complete....