Callbackhandler for TCP Socket

Hi pro’s,

In my Humidor Controll Desktop App, I connect multiple sensors (humidity, temperature) by a TCP-Socket.

So each sensor type has its own class and get instanced with its address and can send a request by TCP-Socket.
nNow the response comes on the TCP-Socket “Data-Available Event”.

How can this Event be passed to the sending sensor instance response handler, so the response can be handled according to the sensor type?
Or need I to hack a synchronius TCP-Socket, waiting on the response?

I red about “addressOf” and “dellegate” but didn’t figure out how exactly that could help me.

Sorry for the diletant question, may somone can give me a hint :slight_smile:

Thanks in advance, Alessandro

Use AddHandler to tie an instance of TCPSocket created in code to a method that will handle the response. The key is the method must have a TCPSocket as its first parameter.

Sub HandlerMethod(sock as TCPSocket)
    dim data as string = sock.ReadAll
    // do something with the data
End // Sub HandlerMethod
dim socket as New TCPSocket
socket.Address = 
socket.Port =
AddHandler socket.DataAvailable, AddressOf HandlerMethod
socket.Connect