connection des deux client
This commit is contained in:
@@ -7,5 +7,10 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Bonjour !</h1>
|
<h1>Bonjour !</h1>
|
||||||
<p>Ceci est une page statique servie par Express.</p>
|
<p>Ceci est une page statique servie par Express.</p>
|
||||||
|
<script src="/socket.io/socket.io.js"></script>
|
||||||
|
<script>
|
||||||
|
const socket = io();
|
||||||
|
console.log("Connecte au serveur, id :", socket.id);
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,12 +1,25 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const http = require('http');
|
||||||
|
const { Server } = require('socket.io');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
const server = http.createServer(app);
|
||||||
|
const io = new Server(server);
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
|
|
||||||
// Sert tous les fichiers du dossier "public"
|
// Sert tous les fichiers du dossier "client"
|
||||||
app.use(express.static(path.join(__dirname, '../client')));
|
app.use(express.static(path.join(__dirname, "..", "client")));
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
io.on("connection", (socket) => {
|
||||||
|
console.log("Un client s'est connecte : ${socket.id}");
|
||||||
|
|
||||||
|
socket.on("disconnect", () => {
|
||||||
|
console.log("Client deconnecte : ${socket.id}");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(PORT, () => {
|
||||||
console.log(`Serveur démarré sur http://localhost:${PORT}`);
|
console.log(`Serveur démarré sur http://localhost:${PORT}`);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user