The connect method does not check for a NULL api before dereferencing it.
There is an inconsistency with the parameters in the connect method. For UDPSocket, address is passed as a pointer, whereas for TCPStream the same parameter is passed as a reference. They should ideally use the same calling style?