aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/Client.hx19
-rw-r--r--examples/Server.hx29
2 files changed, 48 insertions, 0 deletions
diff --git a/examples/Client.hx b/examples/Client.hx
new file mode 100644
index 0000000..675fe94
--- /dev/null
+++ b/examples/Client.hx
@@ -0,0 +1,19 @@
+package examples;
+
+import haxe.io.Bytes;
+import unix.UnixSocket;
+
+class Client {
+ static function main() {
+ var server = new UnixSocket("haxe.sock");
+ server.init();
+ server.connect();
+
+ server.writeBytes(Bytes.ofString("Ping"));
+
+ var receivedData = server.readBytes("Pong".length);
+ trace(receivedData);
+
+ server.close();
+ }
+}
diff --git a/examples/Server.hx b/examples/Server.hx
new file mode 100644
index 0000000..87e00a4
--- /dev/null
+++ b/examples/Server.hx
@@ -0,0 +1,29 @@
+package examples;
+
+import haxe.io.Bytes;
+import sys.FileSystem;
+import unix.UnixSocket;
+
+class Server {
+ static function main() {
+ var server = new UnixSocket("haxe.sock");
+
+ server.init();
+ server.bind();
+ server.listen(5);
+
+ while (true) {
+ trace('Waiting for clients to connect...');
+ var client = server.accept();
+ trace('Accepted connection from client with fd ${client.fileDescriptor}');
+ var receivedData = client.readBytes("Ping".length).toString();
+ trace('$receivedData');
+ client.writeBytes(Bytes.ofString("Pong"));
+ client.close();
+ }
+
+ if (FileSystem.exists("haxe.sock")) {
+ FileSystem.deleteFile("haxe.sock");
+ }
+ }
+}