1socket_connect4(3) Library Functions Manual socket_connect4(3)
2
3
4
6 socket_connect4 - attempt to make a TCP connection
7
9 #include <socket.h>
10
11 int socket_connect4(int s,const char ip[4],uint16 port);
12
14 socket_connect4 attempts to make a connection from TCP socket s to TCP
15 port port on IP address ip.
16
17 socket_connect4 may return
18
19
20 · 0, to indicate that the connection succeeded (and succeeded
21 immediately, if the socket is non-blocking)
22
23 · -1, setting errno to error_inprogress or error_wouldblock, to
24 indicate that the socket is non-blocking
25
26 · -1, setting errno to something else, to indicate that the con‐
27 nection failed (and failed immediately, if the socket is non-
28 blocking).
29
30 When a background connection succeeds or fails, s becomes writable; you
31 can use socket_connected to see whether the connection succeeded. If
32 the connection failed, socket_connected returns 0, setting errno appro‐
33 priately.
34
35 Once a TCP socket is connected, you can use the read and write system
36 calls to transmit data.
37
38 You can call socket_connect4 without calling socket_bind4. This has
39 the effect as first calling socket_bind4 with IP address 0.0.0.0 and
40 port 0.
41
42
44 #include <socket.h>
45
46 int s;
47 char ip[4];
48 uint16 p;
49
50 s = socket_tcp4();
51 socket_bind4(s,ip,p);
52 socket_connect4(s,ip,p);
53
54
56 socket_connect6(3), socket_fastopen_connect4(3)
57
58
59
60 socket_connect4(3)