I found perl has got a library WWW::Google::Cloud::Messaging. I want to maintain a single TCP connection for communicating with GCM rather than opening new connection for individual message. Is this possible using WWW::Google::Cloud::Messaging?
If you want to have a persistent connection for GCM type of messaging rather than having a connection opened everytime you make, You can make use of the libwww library. Please click on the following link to download and learn more about the installation.
Hope that Helps!!
Related
I want to connect to a locally running TCP service from a web application I'm building using the Play framework and scala.
I'm not sure how to open this connection and send commands to it, should I be writing raw socket code? Also, how should I be managing the connection? Can I just open the connection once and send commands from each web request to it? What if the connection is closed or falls over?
Not sure Pay will be of much help here, most of its modules focus on HTTP communication. You should have a look at Akka-IO though.
So I've tested this particular example on my local machine:
http://bjorngylling.com/2011-04-13/postgres-listen-notify-with-node-js.html
It worked! So now when I update a specific table, and am running my node.js file(from the tutorial) -I get an instant notification on my Terminal(mac)!! cool!
But how do I implement this onto a client's browser??
First of all, in the node.js script you'll notice that I have to connect to the database with my username and password:
pgConnectionString = "postgres://username:pswd#localhost/db";
I obviously can't have that floating around in the .js file the user's browser downloaded.
Plus I don't even know what scripts I'd have to include in the <head>. I can't find anything anywhere on how this is used in the real world.... All I see are neat little examples you can use in your command line.
Any advice, or guidance in the right direction would be awesome! Thanks.
You can't.
Node.js runs directly on your server, speaking directly to the native libraries on that machine. I'm not sure exactly what the postgres driver you are using does, but either it speaks to the postgres libraries OR it speaks directly with sockets on the local or a remote database server.
Neither of these methods can be used directly from a browser environment (it can't speak directly to the native libraries and it can't speak "raw" sockets).
What you can do is to have the web client speak to your own server process on a server (running node.js or similar), which would then speak to the database on behalf of the client.
Assuming you also need to database server to be able to initiate notifications to the client, you would need to use a bi-directional communication module like socket.io or similar.
You can do: combine your JS running on node.js which accesses Postgres listening for events with a node.js based WebSocket server, implement PubSub and push out to HTML5 browsers .. WebSocket capable ones.
Another option: use a generic WebSocket to TCP bridge like https://github.com/kanaka/websockify and implement the Postgres client protocol in JS to run in browser. That is doable, but probably not easy / for the faint hearted.
I am working with the BlueZ libraries for managing the bluetooth stack under linux. I am trying to open a socket that should connect with a specific service whose UUID is known. I have successfully tried to open sockets between a server and a client following the examples here:
http://people.csail.mit.edu/albert/bluez-intro/c404.html
where it is also described how to explore services in a remote host; however, what I cannot figure out is how to specify the UUID while connecting the socket. This is something quite straightforward on other contexts, as it happens when using Android libraries; however, with BlueZ I haven't found examples on the web.
Thanks for the help!
Stefano
-- added some details in a reply... don't know if it's right or not; if not, sorry
thanks for your help!
In my post I said I wanted to connect a socket with a specified UUID since I had in mind a function like createRfcommSocketToServiceRecord as can be found in:
http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#createRfcommSocketToServiceRecord%28java.util.UUID%29
which returns a socket given a certain UUID. I am developing two softwares, one being the client and the other the server, therefore it's a service I am creating, not a standard one. I publish such service on the server with a specified UUID, and I would like to connect to it from the client. The server is running fine, since with an android platform, exploiting the mentioned createRfcommSocketToServiceRecord method, I am able to connect to the server with the right service.
The example you posted is very clear as well, but unfortunately it is in Python, while (I forgot to point out) I am using Bluez as a C library. I am able to exploit the SDP and inspect services on a remote server; however, when it is the time of setting up the socket, I don't see how to specify the port. I thought about the rc_channel, but as far as I understood it is the bluetooth channel (ranging from 1 to 11 or something similar). Could you please point out Where I should be able to specify the port while creating the socket in the client? And where am I able to find the right port in the complex structure the sdp is dealing with? -- referred to:
http://people.csail.mit.edu/albert/bluez-intro/x604.html
Thanks again for the help!
You don't connect sockets by UUID. You use a socket to connect to remote device and browse its SDP to discover the UUIDs it offers, and map that to a socket port. Here's an example of this process using PyBluez, python wrappers above BlueZ
http://people.csail.mit.edu/albert/bluez-intro/x290.html
i am newbie to iphone programming. I am working on an iphone project.
My question is:
How to connect my iphone application to a remote server mysql database directly?
There are many ways to connect through PHP scrip/ json/xml/ webservices.
But i dont need that. I would like to have direct connetion to mysql of remote server without any intermediate?
Basically you would need to build a mysql client lib for iOS and then use that from Objective-C. This blog post should get you started. As stated by peko you should really reconsider that you are doing the right thing. The mysql network protocol isn't exactly made for mobile clients where connections can drop, be unavailable, etc.
You shouldn't do this because someone could sniff the traffic and get the username and password for your database, or inject sql-code.
Here's a MySql objective-C client for iPhone. It was traditionally available only for OSX but they just released it for iOS:
http://www.karlkraft.com/index.php/2010/09/17/mysql-for-iphone-and-osx/
I haven't used it. I would still strongly recommend exposing via services. I would also be interested in why you need to directly connect to the DB and why services isn't appropriate :)
I have a simple socket server, that waits for a message and responds. How can I test this? Is there a client app or something that can help me send some data on a specific port to a server, and see the output? Telnet?
Simple telnet client works well for such tests. You can also try PuTTY in either Telnet or Raw connection modes. Both allow you to choose the port you want to connect to.
Also a tool like Microsoft Network Monitor is pretty useful to analyse the protocol's data flow if you don't have direct control (by logs) on what's being sent over the wire.
netcat should be able to handle anything you need to do with socket testing.
http://pctechtips.org/netcat-the-swiss-army-knife-useful-commands/#more-103
Windump - tcpdump works well, and has binaries available to Windows
You have several choices:
1) You can use Chrome or FireFox plugins such as:
Simple WebSocket Client
Smart WebSocket Client
2) You can use WebSocket or ReconnectingWebSocket in JavaScript. this is a simple test with WebSocket:
Open Chrome browser
Press F12 or Right Click on page then click Inspect Element to open developer console
You shoud see a window with several tabs. Go to console tab then write this code.
ws = new WebSocket('ws://<YOUR-DOMAIN>:<PORT>')
ws.send('STH YOU WANT TO SEND')
3) You can use websocket-client. It is a simple python library. You must install python and pip, then websocket-client via pip. This is a simple example:
Go to python shell and type.
from websocket import WebSocket
ws = WebSocket()
ws.connect('ws://<YOUR-DOMAIN>:<PORT>')
ws.send('STH YOU WANT TO SEND')
hit the command line, and just use telnet.
if you have a simple echo server, go to town.