I am developing a game using SocketIO and NodeJS. However, the game currently sends too much data and I would like to figure out why by checking the data being sent every frame. How can I do this?
Open up Chrome's inspect element. Go to the network tab. Enter into the filter tab websocket and you should see a websocket item in the list. When you click on that you can then see "frames". That'll show you the data that socket.io is sending across websockets.
var socket = io();
...
socket.on("channel_data_is_being_sent_on",function(data){
console.log(data);
})
this will log all data being received by the client, from the server, in your console - which you can access in developer tools, generally F12.
Related
I have a websocket that sends some messages to my server and I would like to find out what code is causing the messages to be send.
I can see the websocket and its messages by opening the chrome devtools, going to the network tab, looking for the request of type websocket, clicking on it and going to the tab messages. When looking at the requests in the network tab itself, they have a column Initiator, which links to the code having initialized the request, the same sadly isn't true for the messages overview.
How can I get the same information for each individual message?
Not possible now in Network panel now. I've created a feature request for the Chrome DevTools team in https://crbug.com/1348694. Please leave additional comment on your use case there.
However, one thing you can try is to use debug(function) in the Console, to break on everytime when message is sent. In your case, it could be debug(ws.send).
https://developer.chrome.com/docs/devtools/console/utilities/#debug-function
Ok so for the TCP client in DroidScript, what do I do so that it can receive data from the server at any moment?
The example that is provided shows receiving once only after sending data to the server.
How would i set it up to receive data from the server at any given moment?
I have already tried: net.SetOnReceive and nothing has happened, though i have confirmed data is being sent from the server to the app.
I have also tried net.ReceiveText but I've only received one input from server... but no more after that.
So if anyone could please help?
Screenshot of code:
http://js.x10.bz/ss/i/ZNCj.png
DroidScript TCP sockets are client only (not server). Try using a WebSockets instead and check on the DroidScript forum here:-
https://groups.google.com/d/msg/androidscript/t1QzCgGZrH8/0S8xYbByjNsJ
I'm experimenting broadcasting media (webcam, recorded videos -- like TV) over the internet through websocket (currently only works on Chrome). It is working fine in controlled environment.
However, when put it on test in real life environment most of the times the clients did not receive data sent from the other end.
Here's how I set my websocket configuration (for example only):
var websocket = new WebSocket('ws://74.13.452.171:8080');
websocket.addEventListener("message", function(e) {
// do something with e.data
});
So how to make sure that all clients visiting a certain page of the web site received data sent from another client.
Thanks in advance
I am making a game where a node server speaks to javascript clients using socket.io. Players can connect and disconnect from the game and the server keeps track of who is connected. However, I have found that on many occasions when i close the server, close all open client tabs, then restart a new node server, the number of clients connected seems incorrect.
For example, I will connect with just one client but the node debugger shows that the server is keeping track of three sockets.
This is a problem because often these orphaned clients will receive messages from the server or timeout, and this messes up the game logic on the server (it was not expecting this many players etc.)
I think the reason this is happening is:
1. Clients in socket.io automatically attempt a reconnect periodically when they are disconnected
2. When closing a tab the sockets associated with that page are not being "flushed" or cleared for some reason.
3. When the server is closed and then started up again, these unflushed clients think "oh, the server is back up, i will try and reconnect"
How can I tell the difference between sockets that have had their tabs closed/were associated with the old server, and new clients attempting to connect to the newly restarted server? Or is there a way for me to ensure the clients get "flushed" when either the server is closed or a tab?
Without any code, I am really only guessing here.
http://socket.io/docs/#sending-and-receiving-events
Above, you will find code and I will copy it. Basically, you need to listen to the 'disconnect' event on the socket and remove your reference of the client from whatever array you are using to keep track of your clients.
socket.on('disconnect', function () {
// remove from list here
});
Connections from the browser will die on tab close and this event will be called when this happens. Yes, if you reopen the page, they will reconnect.
You should create some sort of "handshake" that actually adds a client to your list of game clients. Anyone can technically connect to a websocket. It can be as simple as emitting an "init" message that is empty but at least have something there.
I've just completed the simple chat client socket.io tutorial and I am inspecting the messages going between my browser and the Node.js server web socket using the Chrome WebSocket inspector. There are numbers prefixed before the messages as depicted in my screenshot below.
As you can see there are messages with just '2' and '3' and next to my emits there are 42s going back and forth. What do they mean? Is there a list of the main message types I should familiarise myself with so I can learn about debugging Web Sockets?