how to send a value via tcp in rails? - ruby-on-rails

I am developing rails app and following are the things that i have done and i need to do.
I am using rails for iphone app and i have an api for sending the values to the server.
When a user sends the value to the server, the value has to be stored in db and i need to show the values to the other user.
The other user should listen to the tcp server and the value should be received by that user.
I have read few examples from https://www6.software.ibm.com/developerworks/education/l-rubysocks/l-rubysocks-a4.pdf and few other examples but i do not know how to proceed.
Please help me.

You can just use plain http (or https) to communicate with iphone app.

Related

How to connect a device to a Rails server via TCP?

let me explain what I've already completed and what is needed to be done.
What's I've done
Rails server with PG database that returns some data to a user from DB via GET request.
What's needs to be completed
I need to connect the device to this server via TCP. The manufacturer of the device asks me to provide the server address and the port, so he can configure the device to send some messages to the port provided. This messages should be recorded to DB (this part is not important, just to let you know the flow I'm trying to achieve) and then a user can get those messages by GET request mentioned above.
The question
How to set up the Rails server to accept TCP messages from the device to a specified port? How to handle those messages? E.g. the simplest: how to print the message received?
Is it even possible with Rails? If you have a better option on how to achieve the flow mentioned above, please share it.
I'd appreciate some help with code or links.
Just start your rails server with command rails s -b 0.0.0.0
this will bind your public IP with your server so that you can connect with other devices to your rails server.
for example your IP is 192.168.64.40 so, after this command you can do like 192.168.64.40:3000 in to other device's browser so that they can connect to your rails server

Authenticate Username and Password iOS

I have a website that users can log into to see their account info.
I would like to build functionality into my iOS app that allows them to log in and see their info in the app. The usernames and passwords are stored in a SQL database.
How can I authenticate the username and password the user types into the app with the database?
If you have better atuthentication system in your web..
then i would prefer you to use the WEBVIEW for your login page. and continues the other using the normal app flow.
there are lot of tutorials for creating username and password login Function in IOS. i dont know whther you are basic or new progrmmer. But try this you may get some idea.
http://www.youtube.com/watch?v=HrZR2SyeoSk.
You can go with JSON serialisation, if you experienced to load data from server.
There are multiple ways you can go about this but at the end of the day you need an endpoint for your iOS application to talk to your web server. This can be done with a TCP connection (little more complicated) or with a RESTful HTTP API endpoint which is generally the way most developers will go.
To get you running up and quickly on the client side have a look at AFNetworking to do the heavy lifting on your HTTP requests. You will then need a URL on your website that the iOS application can query. Abstract things to keep your API on a different subdomain, say for instance by creating a subdomain to handle your API requests. A login example could look like this
http://api.mysite.com/login
For a PHP based REST API here is a tutorial for you, PHP API or you could use a Node.js framework such as Restify
The general practise is to use JSON encoded data when sending requests back and forth from the server, iOS 7 has built in JSON encoding/decoding, node and PHP also have pretty good support.
Once you are able to send and receive HTTP request from your iOS device to your web server it is just a matter of checking the username and password match up on the server side (seems you already know how to do this?) to the ones in your database and sending back a authentication BOOL and option error message if failed.

iOS: session + changing IP-addresses; how to handle it on the client?

in my iPhone/iPad-app I've got to deal with a server which determines sessions (not only, but also) according to the IP-address. The problem now is that with some providers, the phone's IP address changes after a few seconds and therefore the server can't recognize the session any more.
Is there any way to handle this on the client and "help" the server to stay unchanged without configuration changes? Or is it only possible serverside?
I'm not using a library (ASIHTTP-request, e.g.), but only NSURLConnection.
Nope, nothing you can do client side. You will have to configure the server to accept session ID only.

How do I get the original sender from a forwarded email using Rails 3 mail gem?

I am trying to forward email into my Rails3/Ruby 1.9.2 app and I need to get the sender's email address.
Anyone know how to do this with new Rails 3 mail?
Also can I get the time received or sent from the sender?
According to the docs here
You should just be able to call
mail.envelope_from
Normally the forwarding mail server will pass on the address it's forwarding for as a header. At CloudMailin we are experimenting with passing the header x-forwarded-for which google and some other servers add. It's not garaunteed but if your server sets a header and your only using one it will be consistent so you can rely on it being there.

I can send an email from my Rails app, but not an SMS text through an email gateway

I have application that needs to send emails and sms text messages. It sends emails just fine, but when I try to send text messages using email gateways (for verizon, xxxyyyzzzz#vtext.com) I get nothing. I have texted the phone using though the email gateway using my gmail account, so I know it works. I would just think that from my app's point of view I am just sending out another email. Any idea why this doesn't work? Or what I can do to troubleshoot it?
I should also note that I am doing this from a Rails app on my local computer...not that it should matter.
Maybe Verizon has software that can identify emails sent from software rather than humans, and rejects yours?
Try making your software add all the same headers (eg. X-Mailer) that a normal email client would add.
Verizon could be doing a reverse DNS query as a simple spam check. Your ISP's info could show up during this look up instead of the return address info that your email message contains, and thus could be getting blocked.
To troubleshot this make sure that the return e-mail address that you are using is coming from an ISP e-mail account.
Here is how to debug it on Linux. Run your Rails application server with strace:
strace -s99999 -e connect,read,write,close -o strace.log script/server
Then examine strace.log and see exactly which SMTP server the Rails application connects to, and what it reads and writes.
Then do the same with your favorite mail client (recommended: mutt, because Thunderbird is slow in strace).
Try to send exactly the same bytes from Rails what your mail client sends.
I have used SMS_Fu in the past to send out text messages. It has worked wonderfully.
I have written a client app for Ruby for sending SMS, please see http://freebiesms.blogspot.com/2009/07/send-free-sms-from-ruby.html to download
complete source code.
Regards
Dan

Resources