I've been working on a project to make an Android application using cordova, and I want to use socket.io to interact with the web server, the problem is I can't find detailed information on how the functions work, or event what parameters it's using, or simply I can't figure them out. For example here is my problem:
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="http://cdn.socket.io/socket.io-1.0.3.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
document.addEventListener('deviceready', function() {
var socket = io.connect('http://192.168.1.198:8888');
socket.on('connect', function() {
socket.on('text', function(text) {
alert(text);
});
});
});
</script>
I'm using that as my client and this as my server
var port = Number(process.argv[2]);
var net = require('net');
var timeOut = 1000 * 60;
var server = net.createServer(function (socket) {
socket.setTimeout(timeOut);
socket.setKeepAlive(true,0);
console.log("Socket Start: "+socket.remoteAddress+":"+socket.remotePort);
socket.on('error', function(e) {
console.log(e);
});
socket.on('timeout', function() {
console.log("Socket Timeout: "+socket.remoteAddress+":"+socket.remotePort);
socket.end();
});
socket.on('data', function(data) {
socket.setTimeout(timeOut);
console.log("Socket: "+socket.remotePort+" Sent: "+data.toString());
});
socket.on('end', function() {
socket.destroy();
});
});
if (isNaN(port)) port = 8888;
server.listen(port, '');
console.log("Server listening on Port:"+port);
So the issue is that I'm getting data as if it were an http.request, and that's exactly what I'm trying to avoid when I decided to try my luck with sockets. Here is an example output:
Server listening on Port:8888
Socket Start: 192.168.1.193:58811
Socket: 58811 Sent: GET /socket.io/?EIO=2&transport=polling&t=1427137611586-0 HTTP/1.1 (This is my problem, I don't want this sent)
Host: 192.168.1.193:8888
Connection: keep-alive
User-Agent: Mozilla/5.0 (Linux; Android 4.4.2; sdk Build/KK) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36
So is there any way that the information in "Socket" doesn't get sent by my application?
Accept: */*
Accept-Encoding: gzip,deflate
Accept-Language: en-US
Cookie: io=5lInpN_EHmtL_xfVAAAC
X-Requested-With: socket.io.example