-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLForSocketReceiver.html
More file actions
63 lines (49 loc) · 1.77 KB
/
Copy pathHTMLForSocketReceiver.html
File metadata and controls
63 lines (49 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>Not Working Because Not Complete</h1>
<script>
const port = 8080;
// ایجاد شیء سوکت
const socket = new WebSocket(`ws://localhost:${port}`);
// رویداد دریافت داده از سوکت
socket.onmessage = (event) => {
console.log(`Received: ${event.data}`);
// ارسال پاسخ به سوکت
// socket.send('Hello, client!');
};
// رویداد خطا
socket.onerror = (event) => {
console.error('Error:', event);
};
// بستن سوکت
//socket.onclose = (event) => {
// console.log('Disconnected');
//};
//const net = require('net');
//const server = net.createServer((socket) => {
// console.log('Connected');
// // دریافت داده از سوکت
// socket.on('data', (data) => {
// console.log(`Received: ${data}`);
// // ارسال پاسخ به سوکت
// socket.write('Hello, client!');
// });
// // بستن سوکت
// socket.on('end', () => {
// console.log('Disconnected');
// });
//});
//// پورتی که سرور برای دریافت اطلاعات از آن استفاده میکند
//const port = 8000;
//// شروع سرور
//server.listen(port, () => {
// console.log(`Server listening on port ${port}`);
//});
</script>
</body>
</html>