Forráskód Böngészése

minor adjustmnets

Dr-Swopt 1 hónapja
szülő
commit
19f9c1b2b0

+ 6 - 1
doc/explanation.txt

@@ -60,4 +60,9 @@ it can be reusedd again
 iii) Learn how to use uml to better represents my ideas and absracting a concept so to speak.
 Dont' forget about depedencies injection
 
-
+Note: As for the Http
+- Understandably it works differently, but nevertheless, the existing code to emulate channel via just tranmission and emission will remain the same.
+OF course, ample efforts to use request-response adapter will be allocated to fuflill chin's vision, but nevertheless, the standard channel concept is to 
+be preserveed for consistencies.
+-So going forward, after the UML draft is done, continue with the http development, so that I can test out multiple use of transport services. Of course, I can
+probably also use 2 socket, but it just feels wrong.

+ 2 - 2
src/transmission/msg.transmission.transmitter.ts

@@ -52,9 +52,9 @@ export class MessageTransmissionTransmitter extends MessageTransmissionBase impl
         })
         this.retransmission.implementRetransmission(this.messageToBeTransmitted, this.connectionStateEvent.asObservable(), true)
         // automatically subscribe to allow released bffered messages to be released
-        this.retransmission.returnSubjectForBufferedItems().subscribe((message: WrappedMessage) => {
+        this.retransmission.returnSubjectForBufferedItems().subscribe((bufferedMessage: WrappedMessage) => {
             // need to work with wrapped messages
-            (this.mainAdapter as TransmitterAdapter).emit(message)
+            (this.mainAdapter as TransmitterAdapter).emit(bufferedMessage)
         })
     }
 

+ 40 - 0
src/utils/network.utils.ts

@@ -0,0 +1,40 @@
+const net = require('net');
+
+async function isPortBusy(port:  number, host?: string): Promise<any> {
+  return new Promise((resolve, reject) => {
+    const socket = new net.Socket();
+
+    socket.setTimeout(1000); // Set a timeout for the connection
+
+    // Handle connection success
+    socket.connect(port, host? host : '127.0.0.1', () => {
+      socket.end();
+      resolve(true); // Port is busy
+    });
+
+    // Handle errors (e.g., connection refused)
+    socket.on('error', (err: any) => {
+      if (err.code === 'ECONNREFUSED') {
+        resolve(false); // Port is available
+      } else {
+        reject(err); // Other errors
+      }
+    });
+
+    // Handle timeout
+    socket.on('timeout', () => {
+      socket.destroy();
+      resolve(false); // Port is not responding
+    });
+  });
+}
+
+// Usage example
+const port = 3000;
+isPortBusy(port)
+  .then((busy) => {
+    console.log(`Port ${port} is ${busy ? 'busy' : 'available'}.`);
+  })
+  .catch((err) => {
+    console.error(`Error checking port ${port}:`, err.message);
+  });