wip tests of socket
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
https://www.youtube.com/watch?v=o8Fn9BgqoQM
|
||||
|
||||
npm install --save express
|
||||
npm install --save socket.io
|
||||
sudo npm install -g nodemon
|
||||
first time :
|
||||
npm install --save express
|
||||
npm install --save socket.io
|
||||
sudo npm install -g nodemon
|
||||
|
||||
next time :
|
||||
npm install
|
||||
|
||||
anytime :
|
||||
nodemon server
|
||||
|
||||
|
||||
@@ -6,6 +6,50 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<input type="checkbox" id="chat_input" style="display: none;"/>
|
||||
|
||||
<div class="chat_box">
|
||||
|
||||
<div class="chat_item controls_area">
|
||||
</div>
|
||||
|
||||
<label class="chat_item open_close button" for="chat_input">
|
||||
<p>chat</p>
|
||||
</label>
|
||||
|
||||
<div class="chat_item msg_thread">
|
||||
<div class="msg_box" id="msg_thread">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chat_item msg_write">
|
||||
<div class="text_area" id="msg_write" contenteditable>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="chat_item msg_send button" onclick="submit_new_message()">
|
||||
<p>send</p>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<!-- https://socket.io/docs/v4/client-installation/ -->
|
||||
<!-- https://socket.io/docs/v4/client-api/ -->
|
||||
<script src="https://cdn.socket.io/4.5.3/socket.io.min.js" integrity="sha384-WPFUvHkB1aHA5TDSZi6xtDgkF0wXJcIIxXhC6h8OT8EH3fC5PWro5pWJ1THjcfEi" crossorigin="anonymous"></script>
|
||||
<script>
|
||||
const socket = io("http://localhost:3000");
|
||||
socket.on("connect", () => {
|
||||
console.log("client: connection");
|
||||
});
|
||||
</script>
|
||||
|
||||
<script src="./chat_submit_msg.js"></script>
|
||||
<script src="./chat_receive_msg.js"></script>
|
||||
|
||||
|
||||
<!--
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
|
||||
@@ -30,5 +74,6 @@
|
||||
<input id="message" type="text"/>
|
||||
<button onclick="send()">send</button>
|
||||
</div>
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
let app = require('express')();
|
||||
//let app = require('express')();
|
||||
let http = require('http').Server(app);
|
||||
let io = require('socket.io')(http);
|
||||
|
||||
app.get("/", function (req, res) {
|
||||
console.log("req.headers: ");
|
||||
console.log(req.headers);
|
||||
res.sendFile(__dirname + '/index.html');
|
||||
})
|
||||
//app.get("/", function (req, res) {
|
||||
// console.log("req.headers: ");
|
||||
// console.log(req.headers);
|
||||
// res.sendFile(__dirname + '/index.html');
|
||||
//})
|
||||
|
||||
io.on('connection', function (socket) {
|
||||
|
||||
@@ -26,3 +26,4 @@ io.on('connection', function (socket) {
|
||||
http.listen(3000, function () {
|
||||
console.log('server running on 3000');
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user