Files
Noja/samples/socket.noja
T

28 lines
455 B
Plaintext

addr = "216.58.208.142";
port = 80;
fd = net.socket(net.AF_INET, net.SOCK_STREAM, 0);
if fd < 0:
{
print('Failed to create socket\n');
return none;
}
in_addr = {};
if net.inet_aton(addr, in_addr) == 0:
{
print('Bad address string format\n');
return none;
}
r = net.connect(fd, {sin_family: net.AF_INET, sin_port: net.htons(port), sin_addr: in_addr});
if r < 0:
{
print('Failed to connect\n');
return none;
}
print('Connected!\n');