---
# System prepended metadata

title: Lab 4

---

# Lab 4
[TOC]

## Complete the tasks of [Lab 1](https://hackmd.io/@natanius/Lab-1), using the methods of the WEBSocket protocol.
1. Create a client-server application in javascript using the HTTP protocol that tests the total request to server and back (RTT) travel time with the calculation of **minimum, maximum, median and average RTT, standard deviation and skewness ratio** for client-to-server request frequencies 16Hz, 8Hz, 4Hz, 2Hz, 1Hz, and for client request sizes 128, 256, 512, 1024, 2048 bytes.
Present the results in the form of tables
2. Test the operation of your client-server application on a personal area network (PAN) and on a wide area network (WAN on replit.com hosting). 
3. Estimate the distance to the server and the characteristics of the client-server channel that can be obtained from this data
4. Compare the obtained data with the data of the system network utility ping.


## Results of the test on a personal area network (PAN)
Technical characteristics of the computer on which the experiment was conducted:

    CPU: 
    11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz

    Base speed:            1,80 GHz
    Sockets:               1
    Cores:                 4
    Logical processors:	8


<table id="results-table">
    <thead>
      <tr>
        <th>Freq (Hz)</th>
        <th>Request size</th>
        <th>Total Requests</th>
        <th>Min RTT (ms)</th>
        <th>Max RTT (ms)</th>
        <th>Med RTT (ms)</th>
        <th>Avg RTT (ms)</th>
        <th>STD RTT (ms)</th>
        <th>Skewness Ratio</th>
      </tr>
    </thead>
    <tbody>
      <!-- Results will be dynamically added here -->
    <tr>
        <td>16</td>
        <td>128</td>
        <td>100</td>
        <td>1</td>
        <td>4</td>
        <td>2</td>
        <td>1.86</td>
        <td>0.58</td>
        <td>0.0034</td>
    </tr><tr>
        <td>8</td>
        <td>128</td>
        <td>100</td>
        <td>1</td>
        <td>4</td>
        <td>2</td>
        <td>2.07</td>
        <td>0.75</td>
        <td>0.0032</td>
    </tr><tr>
        <td>4</td>
        <td>128</td>
        <td>100</td>
        <td>1</td>
        <td>4</td>
        <td>2</td>
        <td>2.04</td>
        <td>0.72</td>
        <td>0.0044</td>
    </tr><tr>
        <td>2</td>
        <td>128</td>
        <td>100</td>
        <td>1</td>
        <td>3</td>
        <td>2</td>
        <td>2.17</td>
        <td>0.60</td>
        <td>-0.0009</td>
    </tr><tr>
        <td>1</td>
        <td>128</td>
        <td>100</td>
        <td>1</td>
        <td>4</td>
        <td>2</td>
        <td>2.10</td>
        <td>0.56</td>
        <td>0.0111</td>
    </tr><tr>
        <td>16</td>
        <td>256</td>
        <td>100</td>
        <td>1</td>
        <td>3</td>
        <td>2</td>
        <td>2.00</td>
        <td>0.51</td>
        <td>0.0000</td>
    </tr><tr>
        <td>8</td>
        <td>256</td>
        <td>100</td>
        <td>1</td>
        <td>4</td>
        <td>2</td>
        <td>2.31</td>
        <td>0.70</td>
        <td>0.0018</td>
    </tr><tr>
        <td>4</td>
        <td>256</td>
        <td>100</td>
        <td>1</td>
        <td>4</td>
        <td>2</td>
        <td>2.21</td>
        <td>0.68</td>
        <td>0.0028</td>
    </tr><tr>
        <td>2</td>
        <td>256</td>
        <td>100</td>
        <td>1</td>
        <td>5</td>
        <td>2</td>
        <td>2.28</td>
        <td>0.78</td>
        <td>0.0038</td>
    </tr><tr>
        <td>1</td>
        <td>256</td>
        <td>100</td>
        <td>1</td>
        <td>4</td>
        <td>2</td>
        <td>2.21</td>
        <td>0.67</td>
        <td>-0.0007</td>
    </tr><tr>
        <td>16</td>
        <td>512</td>
        <td>100</td>
        <td>1</td>
        <td>5</td>
        <td>2</td>
        <td>2.47</td>
        <td>1.00</td>
        <td>0.0039</td>
    </tr><tr>
        <td>8</td>
        <td>512</td>
        <td>100</td>
        <td>1</td>
        <td>4</td>
        <td>2</td>
        <td>2.11</td>
        <td>0.77</td>
        <td>0.0047</td>
    </tr><tr>
        <td>4</td>
        <td>512</td>
        <td>100</td>
        <td>1</td>
        <td>5</td>
        <td>2</td>
        <td>2.10</td>
        <td>0.75</td>
        <td>0.0083</td>
    </tr><tr>
        <td>2</td>
        <td>512</td>
        <td>100</td>
        <td>1</td>
        <td>4</td>
        <td>2</td>
        <td>2.12</td>
        <td>0.65</td>
        <td>0.0054</td>
    </tr><tr>
        <td>1</td>
        <td>512</td>
        <td>100</td>
        <td>1</td>
        <td>3</td>
        <td>2</td>
        <td>2.02</td>
        <td>0.62</td>
        <td>-0.0001</td>
    </tr><tr>
        <td>16</td>
        <td>1024</td>
        <td>100</td>
        <td>1</td>
        <td>9</td>
        <td>2</td>
        <td>2.59</td>
        <td>1.08</td>
        <td>0.0223</td>
    </tr><tr>
        <td>8</td>
        <td>1024</td>
        <td>100</td>
        <td>1</td>
        <td>5</td>
        <td>2</td>
        <td>2.21</td>
        <td>0.77</td>
        <td>0.0058</td>
    </tr><tr>
        <td>4</td>
        <td>1024</td>
        <td>100</td>
        <td>1</td>
        <td>4</td>
        <td>2</td>
        <td>2.19</td>
        <td>0.74</td>
        <td>0.0012</td>
    </tr><tr>
        <td>2</td>
        <td>1024</td>
        <td>100</td>
        <td>1</td>
        <td>4</td>
        <td>2</td>
        <td>2.11</td>
        <td>0.65</td>
        <td>0.0080</td>
    </tr><tr>
        <td>1</td>
        <td>1024</td>
        <td>100</td>
        <td>1</td>
        <td>8</td>
        <td>2</td>
        <td>2.14</td>
        <td>1.01</td>
        <td>0.0391</td>
    </tr><tr>
        <td>16</td>
        <td>2048</td>
        <td>100</td>
        <td>1</td>
        <td>5</td>
        <td>2</td>
        <td>2.03</td>
        <td>0.70</td>
        <td>0.0104</td>
    </tr><tr>
        <td>8</td>
        <td>2048</td>
        <td>100</td>
        <td>1</td>
        <td>20</td>
        <td>2</td>
        <td>2.63</td>
        <td>1.93</td>
        <td>0.0753</td>
    </tr><tr>
        <td>4</td>
        <td>2048</td>
        <td>100</td>
        <td>1</td>
        <td>5</td>
        <td>2.5</td>
        <td>2.68</td>
        <td>0.94</td>
        <td>0.0070</td>
    </tr><tr>
        <td>2</td>
        <td>2048</td>
        <td>100</td>
        <td>1</td>
        <td>6</td>
        <td>2</td>
        <td>2.42</td>
        <td>0.92</td>
        <td>0.0096</td>
    </tr><tr>
        <td>1</td>
        <td>2048</td>
        <td>100</td>
        <td>1</td>
        <td>35</td>
        <td>2</td>
        <td>2.74</td>
        <td>3.39</td>
        <td>0.0891</td>
    </tr></tbody>
  </table>
  
### Summary and Conclusions

**Frequency's Influence**: Higher frequencies typically resulted in shorter round-trip times, as seen in the trend of decreasing average and median RTT with increasing frequency.
**Request Size Impact**: Larger request sizes tended to cause longer round-trip times, possibly due to increased processing overhead or network congestion.
**RTT Distribution Analysis**: The skewness ratio offered insights into the RTT distribution shape, with values closer to zero indicating a more symmetrical distribution.
**Potential for Optimization**: Considering the observed metrics, exploring optimizations like adjusting request size or frequency can enhance overall system performance and minimize latency.

## Results of the test on a wide area network (WAN on replit.com hosting).


<table id="results-table">
    <thead>
      <tr>
        <th>Freq (Hz)</th>
        <th>Request size</th>
        <th>Total Requests</th>
        <th>Min RTT (ms)</th>
        <th>Max RTT (ms)</th>
        <th>Med RTT (ms)</th>
        <th>Avg RTT (ms)</th>
        <th>STD RTT (ms)</th>
        <th>Skewness Ratio</th>
      </tr>
    </thead>
    <tbody>
      <!-- Results will be dynamically added here -->
    <tr>
        <td>16</td>
        <td>128</td>
        <td>100</td>
        <td>149</td>
        <td>157</td>
        <td>150</td>
        <td>150.60</td>
        <td>1.61</td>
        <td>0.0167</td>
    </tr><tr>
        <td>8</td>
        <td>128</td>
        <td>100</td>
        <td>148</td>
        <td>183</td>
        <td>151</td>
        <td>152.28</td>
        <td>4.80</td>
        <td>0.0396</td>
    </tr><tr>
        <td>4</td>
        <td>128</td>
        <td>100</td>
        <td>149</td>
        <td>195</td>
        <td>151</td>
        <td>153.09</td>
        <td>7.93</td>
        <td>0.0399</td>
    </tr><tr>
        <td>2</td>
        <td>128</td>
        <td>100</td>
        <td>149</td>
        <td>283</td>
        <td>154</td>
        <td>163.21</td>
        <td>23.31</td>
        <td>0.0297</td>
    </tr><tr>
        <td>1</td>
        <td>128</td>
        <td>100</td>
        <td>148</td>
        <td>234</td>
        <td>151</td>
        <td>154.58</td>
        <td>9.91</td>
        <td>0.0561</td>
    </tr><tr>
        <td>16</td>
        <td>256</td>
        <td>100</td>
        <td>149</td>
        <td>169</td>
        <td>150</td>
        <td>151.27</td>
        <td>3.20</td>
        <td>0.0304</td>
    </tr><tr>
        <td>8</td>
        <td>256</td>
        <td>100</td>
        <td>149</td>
        <td>172</td>
        <td>155</td>
        <td>156.16</td>
        <td>4.95</td>
        <td>0.0102</td>
    </tr><tr>
        <td>4</td>
        <td>256</td>
        <td>100</td>
        <td>148</td>
        <td>171</td>
        <td>151</td>
        <td>152.42</td>
        <td>4.30</td>
        <td>0.0216</td>
    </tr><tr>
        <td>2</td>
        <td>256</td>
        <td>100</td>
        <td>148</td>
        <td>200</td>
        <td>151</td>
        <td>153.53</td>
        <td>9.24</td>
        <td>0.0381</td>
    </tr><tr>
        <td>1</td>
        <td>256</td>
        <td>100</td>
        <td>148</td>
        <td>184</td>
        <td>151</td>
        <td>152.22</td>
        <td>4.71</td>
        <td>0.0382</td>
    </tr><tr>
        <td>16</td>
        <td>512</td>
        <td>100</td>
        <td>148</td>
        <td>156</td>
        <td>150</td>
        <td>150.41</td>
        <td>1.52</td>
        <td>0.0104</td>
    </tr><tr>
        <td>8</td>
        <td>512</td>
        <td>100</td>
        <td>148</td>
        <td>158</td>
        <td>150</td>
        <td>150.62</td>
        <td>2.06</td>
        <td>0.0152</td>
    </tr><tr>
        <td>4</td>
        <td>512</td>
        <td>100</td>
        <td>148</td>
        <td>195</td>
        <td>151</td>
        <td>155.43</td>
        <td>9.92</td>
        <td>0.0222</td>
    </tr><tr>
        <td>2</td>
        <td>512</td>
        <td>100</td>
        <td>148</td>
        <td>233</td>
        <td>151</td>
        <td>154.98</td>
        <td>12.28</td>
        <td>0.0404</td>
    </tr><tr>
        <td>1</td>
        <td>512</td>
        <td>100</td>
        <td>149</td>
        <td>200</td>
        <td>153</td>
        <td>155.85</td>
        <td>9.02</td>
        <td>0.0234</td>
    </tr><tr>
        <td>16</td>
        <td>1024</td>
        <td>100</td>
        <td>148</td>
        <td>167</td>
        <td>150</td>
        <td>150.52</td>
        <td>2.41</td>
        <td>0.0391</td>
    </tr><tr>
        <td>8</td>
        <td>1024</td>
        <td>100</td>
        <td>148</td>
        <td>655</td>
        <td>151</td>
        <td>164.22</td>
        <td>68.30</td>
        <td>0.0589</td>
    </tr><tr>
        <td>4</td>
        <td>1024</td>
        <td>100</td>
        <td>148</td>
        <td>193</td>
        <td>150</td>
        <td>151.22</td>
        <td>4.99</td>
        <td>0.0649</td>
    </tr><tr>
        <td>2</td>
        <td>1024</td>
        <td>100</td>
        <td>148</td>
        <td>170</td>
        <td>150.5</td>
        <td>153.10</td>
        <td>5.46</td>
        <td>0.0156</td>
    </tr><tr>
        <td>1</td>
        <td>1024</td>
        <td>100</td>
        <td>148</td>
        <td>201</td>
        <td>151</td>
        <td>154.82</td>
        <td>9.28</td>
        <td>0.0247</td>
    </tr><tr>
        <td>16</td>
        <td>2048</td>
        <td>100</td>
        <td>148</td>
        <td>182</td>
        <td>151</td>
        <td>153.50</td>
        <td>7.54</td>
        <td>0.0247</td>
    </tr><tr>
        <td>8</td>
        <td>2048</td>
        <td>100</td>
        <td>148</td>
        <td>184</td>
        <td>150</td>
        <td>152.62</td>
        <td>6.88</td>
        <td>0.0318</td>
    </tr><tr>
        <td>4</td>
        <td>2048</td>
        <td>100</td>
        <td>148</td>
        <td>180</td>
        <td>150</td>
        <td>151.77</td>
        <td>5.02</td>
        <td>0.0368</td>
    </tr><tr>
        <td>2</td>
        <td>2048</td>
        <td>100</td>
        <td>148</td>
        <td>187</td>
        <td>151</td>
        <td>155.28</td>
        <td>8.73</td>
        <td>0.0170</td>
    </tr><tr>
        <td>1</td>
        <td>2048</td>
        <td>100</td>
        <td>149</td>
        <td>193</td>
        <td>154</td>
        <td>158.46</td>
        <td>9.79</td>
        <td>0.0157</td>
    </tr></tbody>
  </table>

### Summary and Conclusions

- **Network Type Influence**: PAN usually provides quicker response times and more stable performance in contrast to WAN, given its operation within a smaller, regulated setting.
- **RTT Fluctuations**: WAN shows greater fluctuations in RTT metrics, probably due to issues like network congestion, packet loss, and longer distances between nodes.
- **Potential for Enhancements**: Although PAN may need fewer enhancements due to its inherently stable nature, optimizing WAN performance can greatly benefit from improvements aimed at enhancing network efficiency, managing congestion, and upgrading protocols.


## Code

### File: server.js
```javascript
const app = express();
  const server = http.Server(app);
    const io = socketIO(server);

io.on('connection', socket => {
  socket.on('getRTT', (data, clientCounter) => {
    const socketName = 'Client' + clientCounter;
      socket.emit(socketName, data, clientCounter);
  });

  socket.on('disconnect', () => {
    console.log('User disconnected');
  });
});

server.listen(3000, "127.0.0.1", () => {
  console.log('Server running at http://127.0.0.1:3000/');
});
```
This script establishes a live communication system in a Node.js app using Socket.IO. It awaits client connections and records user connection and disconnection events. When a client sends a message labeled 'measureRTT', the server logs the data received, then sends a confirmation message back to the client containing the same data.


### File: script.js

```javascript
function requestToServer(requestSize) {
  const data = generateData(requestSize);
  const startTime = Date.now();
  const localCounter = counter;
    counter++;
    const socketName = 'Client' + localCounter;

      socket.on(socketName, (responseData, recievedCounter) => {
        const rtt = Date.now() - startTime;
          const sizeInBytes = responseData.length;
            console.log('Response size:', sizeInBytes, 'bytes');
              calculateMetrics(rtt);
      });
                socket.emit('getRTT', data, localCounter);
}
```
This code creates a function called `requestToServer(requestSize)` which is responsible for sending a message to the server to measure the round-trip time (RTT) using the specified request size. It generates data according to the given request size, starts recording the time, and then sends this data to the server using the event name `'measureRTT'`. Additionally, it listens for a response event named `'RTTMeasured'` from the server. Upon receiving this response, it calculates the RTT, logs it along with the response size, and proceeds to calculate various metrics based on the RTT.

[**Сode on replit**](https://replit.com/@eFediaieva/Lab4)

## Results of ping:

```
[anonymous@2ip ~]$ ping -c 10 https://7f3fc2e9-4d49-44be-ab2f-7786b5498561-00-29zyzmnxik3lo.janeway.replit.dev/
PING 7f3fc2e9-4d49-44be-ab2f-7786b5498561-00-29zyzmnxik3lo.janeway.replit.dev (34.148.134.19): 56 data bytes
64 bytes from 19.134.148.34.bc.googleusercontent (34.148.134.19): icmp_seq=0 ttl=57 time=97.200 ms
64 bytes from 19.134.148.34.bc.googleusercontent (34.148.134.19): icmp_seq=1 ttl=57 time=97.100 ms
64 bytes from 19.134.148.34.bc.googleusercontent (34.148.134.19): icmp_seq=2 ttl=57 time=96.900 ms
64 bytes from 19.134.148.34.bc.googleusercontent (34.148.134.19): icmp_seq=3 ttl=57 time=97.200 ms
64 bytes from 19.134.148.34.bc.googleusercontent (34.148.134.19): icmp_seq=4 ttl=57 time=97.200 ms
64 bytes from 19.134.148.34.bc.googleusercontent (34.148.134.19): icmp_seq=5 ttl=57 time=97.100 ms
64 bytes from 19.134.148.34.bc.googleusercontent (34.148.134.19): icmp_seq=6 ttl=57 time=96.800 ms
64 bytes from 19.134.148.34.bc.googleusercontent (34.148.134.19): icmp_seq=7 ttl=57 time=97.100 ms
64 bytes from 19.134.148.34.bc.googleusercontent (34.148.134.19): icmp_seq=8 ttl=57 time=97.200 ms
64 bytes from 19.134.148.34.bc.googleusercontent (34.148.134.19): icmp_seq=9 ttl=57 time=97.100 ms
--- 7f3fc2e9-4d49-44be-ab2f-7786b5498561-00-29zyzmnxik3lo.janeway.replit.dev ping statistics ---
10 packets transmitted, 10 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 96.800/97.090/97.200/0.130 ms
```

Distance between local machine and repl.it: 10301.42 km


## Speed of the signal

The signal's speed depends on the medium it travels through, typically slower than the speed of light in a vacuum (approximately 299,792,458 m/s). For instance, in a coaxial cable, it's about 2/3 the speed of light, around 200 km/ms. This means a signal would cover 27,400 km in 137 ms, though actual speeds can vary.

## Conclusions

An RTT of 137 ms means the signal traveled about 27,400 kilometers round trip between source and destination, halving the distance between servers to 13,700 km. Similarly, with an RTT of 150 ms, the signal journeyed approximately 30,000 kilometers round trip, reducing the server distance to 15,000 km.

According to data from 2ip.ua, the distance between me and the repl.it server is 10,301.42 km.

Signal frequency impacts transmission speed. High-frequency signals can transmit faster due to shorter pulse intervals, though this can cause dispersion issues over long distances. Conversely, low-frequency signals have longer pulse intervals but may handle distance better, balancing speed and resilience based on the medium and signal characteristics.