I am new in socket.io. I wanted to develop an small application using it. I know the basic of socket.io. I have followed this and this documentation.
I am also able to make this simple connection. Code :
Client:
<script src="/socket.io/socket.io.js"></script>
<script>
console.log(location.protocol+'//'+location.host);
var socket = io.connect(location.protocol+'//'+location.host), socketwithApi = io.connect(location.protocol+'//'+location.host + '/apikey/');
</script>
<script type="text/javascript">
var i=0;
$(document).on('click','#socket-emit-btn', function(){
let message = location.href;
socket.emit("test",message);
});
socket.on("testlistened",function(data){
i ++;
console.log(i);
console.log(data);
if(data){
$("#console-div").html(data);
}else{
$("#console-div").html("{empty}");
}
});
socketwithApi.on('apikey',function(data){
console.log(data);
});
</script>
Server:
//consider everything needed is defined
var apikey = io
.of('/apikey/')
.on('connection', function (socket) {
socket.emit('apikey', { news: 'item' });
});
io.on('connection', function (socket) {
let clientID = socket.id
let clientIP = socket.handshake.address
if (client) client.socket = socket
console.log('User-Client Connected!: IP: ' + clientIP)
socket.on("test",function(data){
console.log("listened");
let ParsedData = url.parse(data);
let responseData = {
UrlScheme:ParsedData,
socketID: clientID,
api_key: ParsedData.pathname
}
console.log(responseData);
console.log(`${TRANSACTIONGETRECEIPT}_RESPONSE`)
socket
.binary(true)
.emit('testlistened', JSON.stringify(responseData))
});
socket.on('disconnect', function (data) {
console.log(clientID + ' has disconnected')
})
})
Everything is working fine, i am able to emit and listen both from the server side and client side. But I did not find the documentation which would tell if it is possible to send http get or post request from the browser or postman to socket.io . Is it only possible to send request from a page where socket client is present or can we also send request like
http://localhost:8099/api-hastgraph-key/socket.io/?EIO=3&transport=websocket&sid=w0kDs4oGI7SVwB3YAAAC
or http://localhost:8099/socket.io/api-hastgraph-key?EIO=3&transport=websocket&sid=w0kDs4oGI7SVwB3YAAAC
from browser and connect to socket.
Thank you. Any kind of help are highly appreciated.