0

I want to send a POST or GET data in socket.io but I can't receive any data. I want to send the data outside the connection. Below is my code:

Server code: app.js

io.sockets.on('connection', function (socket) {
    console.log('You Have successfully Connected to the server');
});

io.sockets.on('checkUser', function (data) {
    io.sockets.emit('callback', {
        data: data
    });
});

Client Side: app.js

$('.key').click(function () {
    var splitItem = $(this).find('.inputKey').val().split('-');;
    var info = {
        userid: user_id,
        itemid: splitItem[0], // keyid
        box: splitItem[1], // boxid
        username: username,
    }
    socket.emit('checkUser', {
        data: info 
    });
});

socket.on('callback', function (data) {
    console.log(data);
});
2
  • what do you mean by outside the connection? did you call listen() on the server? and connect() on the client as shown at socket.io ? Commented Nov 14, 2013 at 5:00
  • i just want to send a POST or a GET..so that i can run my MYSQL QUERY Commented Nov 14, 2013 at 5:04

1 Answer 1

3

if you just want to send a simple http call think again if you have to use socket.io, socket.io built mainly for sending data between client and server in realtime.

to use node.js for querying your mysql database and much more check out http://expressjs.com/ web application framework

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.