qlibs:(socket_connect)
π qlibs:(socket_connect) β manual section 3, bestie π
πΈ NAME πΈ
okay so socket_connect is the one that initiates or tests a socket connection to a remote IPv4/IPv6 address. literally the βcan we talk?β of sockets. π
β¨ SYNTAX β¨
First, include this:
#include "socket_if.h"
Then the signatures, exactly:
int socket_connect4(int s,const char ip[4],uint16 port);
int socket_connect6(int s,const char ip[16],uint16 port,
uint32 scope_id);
int socket_connect(int s,const char ip[16],uint16 port,
uint32 scope_id);
int socket_connected(int s);
π¦ DESCRIPTION π¦
socket_connect4 tries to make a connection from TCP or UDP socket s to TCP port port on IP address ip. You can call socket_connect4 without calling socket_bind4 first β thatβs giving βfirst call socket_bind4 with IP address 0.0.0.0 and port 0β energy. β¨
socket_connect6 tries to make a connection from TCP or UDP socket s to TCP port port on IP address ip and scope_id. The meaning of scope_id depends on the implementation and IPv6 IP. For link-local IPv6 addresses it specifies the outgoing interface index. From a given interface name (e.g. "eth0") its index can be retrieved with socket_getifidx. scope_id should normally be set to 0. You can call socket_connect6 without calling socket_bind6 first β thatβs the same effect as first calling socket_bind6 with IP address :: and port 0. π
socket_connect tries to make a connection from TCP socket s to TCP port port on IP address ip and scope_id by calling socket_connect6. If, however, ip is an IPv4 or IPv4-mapped IPv6 address, socket_connect4 is called instead. iykyk. π
Once a socket is connected, you can use the read and write system calls to transmit data. slay. π
socket_connected can be used to verify whether a background connection failed or succeeded β thus whether s became writable or not. vibe check for your socket. π
π EXAMPLE π
#include <socket_if.h>
int s;
char localip[16];
char remoteip[16];
uint16 p = 0;
s = socket_tcp();
socket_bind(s,localip,p,0);
socket_connect(s,remoteip,p,0);
if (socket_connected(s) != 1)
err_tmp(""111,fatal,"unable to setup TCP connection: ");
π₯ RETURN CODES π₯
socket_connect4,socket_connect6andsocket_connectβ may return0to indicate that the connection succeeded (and succeeded immediately, if the socket is non-blocking). π- They may return
-1, settingerrnotoerror_inprogressorerror_wouldblock, to indicate that the socket is non-blocking. π«Ά - They may return
-1, settingerrnoto something else, to indicate that the connection failed (and failed immediately, if the socket is non-blocking). π
socket_connected returns 1 if s is a socket and a connection is established, 0 otherwise and setting errno appropriately. no cap. π―
π SEE ALSO π
socket_if(3)socket_info(3)socket_bind(3)socket_recv(3)socket_send(3)socket_setup(3)socket_tcp(3)socket_udp(3)
byeee bestie β this page is manual section 3, source/version qlibs:(socket_connect), and thatβs the footer tea π«Άπ
β¨
π¦ where this page comes from
- alpine 3.24: fehqlibs-doc 31-r0 Β· Public-Domain
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms