connection des deux client
This commit is contained in:
@@ -7,5 +7,10 @@
|
||||
<body>
|
||||
<h1>Bonjour !</h1>
|
||||
<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>
|
||||
</html>
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const http = require('http');
|
||||
const { Server } = require('socket.io');
|
||||
|
||||
const app = express();
|
||||
const server = http.createServer(app);
|
||||
const io = new Server(server);
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
// Sert tous les fichiers du dossier "public"
|
||||
app.use(express.static(path.join(__dirname, '../client')));
|
||||
// Sert tous les fichiers du dossier "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}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user