From c8a987daefa1475b1902b9823e8d2ef4500943cd Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Thu, 29 Jun 2023 01:47:35 -0500 Subject: Sockets update --- examples/client.sloth | 21 ++++++++++++++++----- examples/server.sloth | 12 +++++++++--- 2 files changed, 25 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/client.sloth b/examples/client.sloth index 8b7f737..26a902f 100644 --- a/examples/client.sloth +++ b/examples/client.sloth @@ -1,9 +1,20 @@ fn main() Int { - var sockint: Int = clientsock(); + var sockint: Int = clientsock(8080, "127.0.0.1"); println(recvsock(sockint)); - while true { - sendsock(readln(), sockint); - } - closesock(sockint); + var con: Bool = true; + while con == true { + print("send> "); + var msg: String = readln(); + sendsock(msg, sockint); + if sequals(msg, "KILLCLIENT") { + con = false; + } + println("wait..."); + msg = recvsock(sockint); + print("server: "); + println(msg); + + } + closesock(sockint, false); return 0; } diff --git a/examples/server.sloth b/examples/server.sloth index 201f8a2..3329471 100644 --- a/examples/server.sloth +++ b/examples/server.sloth @@ -1,14 +1,20 @@ fn main() Int { - var sockint: Int = serversock(); + var sockint: Int = serversock(8080, "auto", 10); + println("slothnet has initialized!"); sendsock("Welcome to slothnet!", sockint); var con: Bool = true; while con == true { + println("wait..."); var msg: String = recvsock(sockint); + print("client: "); println(msg); - if sequals(msg, "kill") { + print("send> "); + msg = readln(); + sendsock(msg, sockint); + if sequals(msg, "KILLSERV") { con = false; } } - closesock(sockint); + closesock(sockint, true); return 0; } -- cgit v1.2.3