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
Related
I have a device that is connected to a Node server via WebSockets. To be able to query the device, a POST request to that server sends the necessary command via WebSockets. However, I'm not entirely sure what the best method of implenting getting the return is.
The flow is essentially:
Device connects to Node server via WebSockets
User sends POST request to endpoint on the same Node server
Node server sends the suitable command to the device via WebSockets
Device replies via WebSockets
This is where I'm stuck. How do I get the reply from WebSockets back to the POST request?
My first thoughts were as such:
The POST request knows what command has been sent
The device sends back the command as part of the WebSocket reply
Therefore, I can just have a simple array of messages from the device that the POST request function can poll, and if there's suitable reply (say within 2 seconds), reply with that data and delete the message from the array. Further down the line, I can delete any messages that have expired but are still in the array.
What are my other options? Presumably I could poll from the client doing the POST request or alternatively connect that client via a WebSocket.
This server supports 1 device and usually 1 user at a time, so there isn't really any worry that the server could become overwhelmed.
Good day! Where does all data send when nodejs method socket.write is called? I understand that socket runs of the server side for each client. But where exactly does data go? to client? On official nodejs documentanion there is no info about destination. Thank you for response.
You cannot successfully write to a socket unless you (or some part of your nodejs software) first connects it to some other socket somewhere.
A socket server listens for connection requests, and then accepts them as they arrive. (When you use node express to make a web server, express handles this for you.) A client connects to a socket server. Once the pair of sockets are connected, data you write into one of the sockets causes a data event on the other one.
The two sockets may be on different machines in different locations. That's the miracle of global networking.
So where does data you write go? To the other socket in the pair.
If you are using datagrams (not connections) it's slightly different. The data you write contains the destination address. But you probably are not using databgrams. If you are, you are probably using a protocol stack like RTSP or UDP instead of TCP.
I have a JavaScript/html web socket client. It receives images from my server quite frequently. I am hosting my web socket server in a C# console application.
The longest my client has to wait for an image is 10 seconds.
Should I also be sending 'keep-alive' packets from my client (JavaScript) to my Server or is the fact that it receives regular data packets from my server enough?
Thanks
You can send ping messages from the server, and the client will answer with a pong message. It is part of the WebSocket protocol, not sure if your server implementation supports it. However, from the client you have no way to know if you got a ping message in while, so the client may be let hanging there.
Or you can do it at application level using your own messages. Basically create a "ping" message in JSON and send it regularly from the client to the server, then if you do not get a response in X time, reconnect.
If you don´t, the only problem is that the connection maybe half-open, and your client may be hanging there waiting for a image that will never come.
Cheers.
Here's the scenario, I have a client side application, served by PHP on a different server to the node.js + socket.io application. It can connect and receive broadcasts sent from the server. If the connection drops, the application falls back to polling a database (using setInterval()). It attempts to reconnect every 5 polls, and it can successfully reconnect and continue to receive messages.
My problem occurs when the user loads the page and the node server cannot be reached (I turned it off for testing), I then turn on the server and on the 5th poll, it successfully connects to the server, using socket.socket.reconnect();. However, whenever the server broadcasts messages, it doesn't fire the event. Note that this doesn't happen when testing on a phone (which falls back to a different socket method)
I have already seen the question found here Reconnection in socket.io problem in `socket.on('message',function(){})`, however, the socket has not previously been connected so I don't think it could be the session?
EDIT: I changed the socket.socket.reconnect() to socket.socket.connect() and it fixed the problem. If someone could explain the reasons of why this works I'd like to know. I know its because the server isn't actually reconnecting, but would like more info.
Thanks.
well you possibly know the reason for this. server is not reconnecting. it is actually connecting. when you tell socket.io to reconnect it searches for the previous connection handle and thats where the problem arises.
I have written an application in DHTML using OpenLaszlo. The application works perfectly fine in Chrome, but it is having problems in Firefox. The javascript client makes HTTP POST requests to a Struts2 middle layer, which queries the database via Hibernate and then returns an XML response. The application is in production, so the client code, middle layer and database are all hosted on my desktop machine.
I can literally run the application in Chrome and Firefox side-by-side, and while everything works perfectly in Chrome, a few of the HTTP requests (the same ones every time) will fail on Firefox. The ones that fail do so immediately after the POST request is initiated, with no HTTP response or error code given (I am using Firebug to watch the POST requests and responses).
After watching the traffic with Wireshark I have determined that, for some reason, Firefox is sending a FIN ACK packet immediately (less than a second) after making the POST request and receiving the standard ACK from the server.
The network traffic looks like this:
In Chrome: Client sends POST -> Server sends ACK -> Server sends XML data -> Client sends ACK -> Server sends HTTP/XML 200 Response -> Client sends ACK
In Firefox: Client sends POST -> Server sends ACK -> Client sends FIN, ACK -> Server sends ACK -> Server sends XML data -> Client sends a reset
I am wondering if anyone has witnessed this type of behavior before, and might know what I can do to fix it.
i also encountered this issue. Firefox send FIN,ACK related to its new network change feature. see: https://hg.mozilla.org/mozilla-central/rev/0a066b7ffa46
we spend huge time in checking this.
i have also an post at stackoverflow: when firefox 38 sent FIN,ACK after server ack an http get from firefox?
for anyone interested in this, please track: bugzilla.mozilla.org/show_bug.cgi?id=1245059 workaround solution is to set "network.http.network-changed.timeout” setting bigger. check our reported firefox bug for more detail.