Open LokeshPatel opened 8 years ago
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"];
[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
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:
Send message/event not working . Event:
Message:
[socketIO sendMessage:@"Hello abc 12345"];
Server side code: (Node.js)
Thanks, Lokesh Patel