added send and recv builtins
This commit is contained in:
+11
-1
@@ -23,4 +23,14 @@ if net.connect(fd, { sin_family: net.AF_INET, sin_port: net.htons(port), sin_add
|
||||
return none;
|
||||
}
|
||||
|
||||
print('Connected!\n');
|
||||
print('Connected!\n');
|
||||
|
||||
buffer = newBuffer(16);
|
||||
|
||||
buffer[0] = 9;
|
||||
buffer[1] = 7;
|
||||
buffer[2] = 255;
|
||||
|
||||
n = net.send(fd, buffer, 0);
|
||||
|
||||
print('Sent ', n, ' bytes: ', buffer, '\n');
|
||||
+18
-1
@@ -22,6 +22,8 @@ if net.listen(fd, backlog) != 0:
|
||||
return none;
|
||||
}
|
||||
|
||||
buffer = newBuffer(16);
|
||||
|
||||
while true:
|
||||
{
|
||||
client_addr = {};
|
||||
@@ -34,5 +36,20 @@ while true:
|
||||
print('client_fd = ', client_fd, '\n');
|
||||
print('client_addr = {', client_addr, '}\n');
|
||||
|
||||
# ..continue..
|
||||
do
|
||||
{
|
||||
n = net.recv(client_fd, buffer, 0);
|
||||
|
||||
if n < 0:
|
||||
print('Warning! Failed to read from socket!\n');
|
||||
else if n == 0:
|
||||
{
|
||||
# Client disconnected.
|
||||
}
|
||||
else
|
||||
{
|
||||
print('Received ', n, ' bytes: ', buffer, '\n');
|
||||
}
|
||||
}
|
||||
while n > 0;
|
||||
}
|
||||
Reference in New Issue
Block a user