Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Never send Event/Message from client (iOS) to server (Node.js) #226

Open
LokeshPatel opened this issue Apr 27, 2016 · 0 comments
Open

Never send Event/Message from client (iOS) to server (Node.js) #226

LokeshPatel opened this issue Apr 27, 2016 · 0 comments

Comments

@LokeshPatel
Copy link

I have tried lot's but not getting success, please suggest me how to send messages event from iOS client to server (Node.js).
I have used below code for Client side:

Connect host working proper:

    socketIO = [[SocketIO alloc] initWithDelegate:self];
    [socketIO connectToHost:HOSTURL onPort:PORT];

Send message/event not working .
Event:

 NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:@"123124238029850485" forKey:@"id"];
    [socketIO sendEvent:@"message" withData:dict];

Message:
[socketIO sendMessage:@"Hello abc 12345"];

Server side code: (Node.js)

var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');
var users={};
var clients = {};
function handler (req, res) {
    var filePath = '.' + req.url;
  fs.readFile(filePath,//__dirname + '/index.html',
  function (err, data) {
      console.log("connnected from ios")
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }
    res.writeHead(200);
    res.end(data);
  });
}
app.addListener('request', function(req,res){
    console.log(req.headers);
});
app.listen(8080);
io.on('connection', function (socket) {
   socket.on('message', function (data) {
     console.log(" message  ===== " + data);
});
  socket.on('disconnect', function() {
    console.log("Disconnected >"+socket.id);
  });

});

Thanks,
Lokesh Patel

@LokeshPatel LokeshPatel changed the title Never send event from client to server Never send Event/Message from client (iOS) to server (Node.js) Apr 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant