* * *

Author Topic: Need to read a simple string stream from an IP address  (Read 1452 times)

AlanTheBeast

  • New member
  • *
  • Posts: 40
Need to read a simple string stream from an IP address
« on: September 25, 2016, 07:47:53 pm »
Hi,

I don't use Lazarus, just FPC command line (via Lightweight).

I have a nifty app on my iPhone called SensorLog and it will output whatever sensor data from the phone one sets up to an IP address and a set port.  I can telnet that to the terminal such as
 
$ telnet 192.168.1.22 60444
or
$ telnet 192.168.1.22 60444 > a_file.csv

but I can't get a named pipe or directed pipe to read in the stream.

Is there some "light" unit that will allow me to read the stream?

Something like

     - set an IP address and port as a textfile or a stream
     - read from it until dizzy
     - close when done


Thanks

Phil

  • Hero Member
  • *****
  • Posts: 2070
Re: Need to read a simple string stream from an IP address
« Reply #1 on: September 25, 2016, 07:51:39 pm »
Not sure if I follow.

Does an HTTP request using FPC's TFPHTTPClient class work? (fphttpclient unit)


AlanTheBeast

  • New member
  • *
  • Posts: 40
Re: Need to read a simple string stream from an IP address
« Reply #2 on: September 26, 2016, 12:51:42 am »
I don't know Phil - but now that you've pointed me at that unit I'll see what I see!


Phil

  • Hero Member
  • *****
  • Posts: 2070
Re: Need to read a simple string stream from an IP address
« Reply #3 on: September 26, 2016, 01:00:49 am »
I might have misunderstood what you're doing.

Are you using telnet on a computer as a way to read from the iOS app sends?

I think that for an HTTP request to work, the iOS app would need to act like a Web app running under a Web server. That is, when it receives a request for data, it returns it in a response. From the description on the app store, it appears as though it SensorLog can do that:

https://itunes.apple.com/us/app/sensorlog/id388014573?mt=8

I believe iOS includes a Web server (Apache) because I've seen an iOS app that works like a Web app. Perhaps SensorLog is using the server to service the HTTP requests.




Thaddy

  • Hero Member
  • *****
  • Posts: 3663
Re: Need to read a simple string stream from an IP address
« Reply #4 on: September 26, 2016, 06:30:00 am »
Http should work since it is explicitly supported by SensorLog. see docs in appstore that reads: per HTTP GET/POST.

In that case it should be very easy with TFPHttp and trivial with synapse.

[edit]
The httpget example in /packages/fcl-web/examples/httpclient/ works straight out of the box, tested against an apache server.
usage: httpget <url> <filename>

With synapse use:
Code: Pascal  [Select]
  1. function HttpGetText(const URL: string; const Response: TStrings): Boolean;// in httpsend.pas

There's TCP/IP only streaming client example in this blogpost by forum member leledumbo:
http://pascalgeek.blogspot.nl/2012/06/encryption-decryption-and-asynchronous.html
Scroll-down a bit.
« Last Edit: September 26, 2016, 06:54:57 am by Thaddy »
Why do the Danish always try to fuck up any programming language?

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus