Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.
This repository was 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

Description

@LokeshPatel

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions