Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GET/ socket io not found 404 #1

Open
BilelAyech opened this issue May 1, 2023 · 0 comments
Open

GET/ socket io not found 404 #1

BilelAyech opened this issue May 1, 2023 · 0 comments

Comments

@BilelAyech
Copy link

I need your help after I upgrade the dependencies to "socket.io": "^4.6.1" ...I am getting an error in the console of the browser : GET http://127.0.0.1:5500/socket.io/?EIO=4&transport=polling&t=OVI3WYK 404 (Not Found)
below is my code

my server:

var http = require('http');
var fs = require('fs');
var index = fs.readFileSync( 'index.html');

const { SerialPort } = require('serialport')
const { ReadlineParser } = require('@serialport/parser-readline')

const parser = new ReadlineParser({ delimiter: '\r\n' });

var port = new SerialPort(
    { path: 'COM3', baudRate: 9600 , dataBits: 8, parity: 'none', stopBits: 1, flowControl: false}
    );

port.pipe(parser);
var app = http.createServer(function(req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end(index);
});
var io = require('socket.io')(app);

io.on('connection', function(socket) {
    
    socket.on('lights',function(data){
        
        console.log( data );
        
        port.write( data.status );
    
    });
    
});

app.listen(5500);

my index.html:

<!doctype html>
<html>
    <head>

        <title>Communicating from Node.js to an Arduino</title>
        <script src="https://cdn.socket.io/4.6.1/socket.io.min.js"></script>

    </head>
    <body>

        <h1>Communicating from Node.js to an Arduino</h1>

        <button id="lightOn">Turn Light On</button>
        <button id="lightOff">Turn Light Off</button>

        <script>
            
        var socket = io();

        document.getElementById('lightOn').onclick = function() {
            
            socket.emit('lights', { "status":"1" });
                
        };
            
        document.getElementById('lightOff').onclick = function(){
               
            socket.emit('lights', { "status":"0" });
            
        };
        
        </script>
        
    </body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant