summaryrefslogtreecommitdiff
path: root/graphs/js/advancedCommunication/client.js
diff options
context:
space:
mode:
Diffstat (limited to 'graphs/js/advancedCommunication/client.js')
-rw-r--r--graphs/js/advancedCommunication/client.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/graphs/js/advancedCommunication/client.js b/graphs/js/advancedCommunication/client.js
new file mode 100644
index 0000000..7c051a8
--- /dev/null
+++ b/graphs/js/advancedCommunication/client.js
@@ -0,0 +1,26 @@
+const WebSocket = require("ws");
+
+function addClient(userName) {
+ const socket = new WebSocket("ws://localhost:8080?username=" + userName);
+
+ socket.on("open", () => {
+ socket.send(userName + ": trying to establish connection");
+ });
+ socket.on("close", (code, reason) => {
+ console.log(
+ "<server to " +
+ userName +
+ ">: Connection has been closed: [" +
+ code +
+ "] " +
+ reason,
+ );
+ });
+ socket.on("message", (data) => {
+ console.log("<server to " + userName + ">: " + data);
+ });
+ return socket;
+}
+module.exports = {
+ addClient,
+};