How work with socket?

Why are you doing things at this low level? Wouldn’t it be easier to use ODBC?
https://www.swi-prolog.org/pldoc/doc_for?object=section(‘packages/odbc.html’)