CommStreams

Usage of the framework, compiler and tools
cfbsoftware
Posts: 55
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

Re: CommStreams

Post by cfbsoftware »

DGDanforth wrote:I ran Chris' program and it worked!
I'm pleased to hear that - but Ivan deserves the credit for the program :D
User avatar
DGDanforth
Posts: 59
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, CA, U.S.A.
Contact:

Re: CommStreams

Post by DGDanforth »

I am not having much luck in reading bytes from a web site.
I get no errors but the number of bytes returned is zero.
How do I read bytes from "google.com"?

Code: Select all

(s: Stream) ReadBytes (VAR x: ARRAY OF BYTE; beg, len: INTEGER; OUT read: INTEGER), NEW, ABSTRACT;

Code: Select all

s.ReadBytes(x, 0, len, read);

Code: Select all

CONST len = 1024; 
User avatar
Ivan Denisov
Posts: 362
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: CommStreams

Post by Ivan Denisov »

To communicate with modern websites you should parse responses according HTTP 1.1 standard. There are possible redirects, chunked answers etc.
You can use my solution as I mentioned before viewtopic.php?f=32&t=208#p1363
There are basic support for HTTP standard there.
Josef Templ
Posts: 262
Joined: Tue Sep 17, 2013 6:50 am

Re: CommStreams

Post by Josef Templ »

If there are any problems with downloading, it may be required to look into the responses
provided by the http server directly. I don't know if this is possible with Ivan's program.

If it is not possible you can use the sample program I have posted earlier in this topic.
It shows the response header and the body in a text view.
Replacing the URL related info should be obvious, but note that there are several places.

As Ivan pointed out before, you need to know the HTTP 1.1 standard or at least HTTP 1.0
in order to fully understand the meaning of the many optional and/or mandatory parameters passed
in a http request and response header. This can be challenging, very challenging.

Some things, however, can be read directly because it is in plain English.
Important are the error codes at the first line of the response.
200-399 mean some form of success
400 - 499 mean an error i the request
500 - ... mean an error in the server

- Josef
User avatar
DGDanforth
Posts: 59
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, CA, U.S.A.
Contact:

Re: CommStreams

Post by DGDanforth »

Josef Templ wrote:If there are any problems with downloading, it may be required to look into the responses
provided by the http server directly. I don't know if this is possible with Ivan's program.

If it is not possible you can use the sample program I have posted earlier in this topic.
I don't see your program on this thread.
Josef Templ wrote:it shows the response header and the body in a text view.
Replacing the URL related info should be obvious, but note that there are several places.

As Ivan pointed out before, you need to know the HTTP 1.1 standard or at least HTTP 1.0
in order to fully understand the meaning of the many optional and/or mandatory parameters passed
in a http request and response header. This can be challenging, very challenging.
I am not to that point yet. I can not see any data from the website.
User avatar
Ivan Denisov
Posts: 362
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: CommStreams

Post by Ivan Denisov »

To get any data you need to ask server to send them.

In my example there is the line:

Code: Select all

stream.Send("GET /" + par$ + " HTTP/1.1" + 0DX + 0AX + "Host: " + host$ + 0DX + 0AX + 0DX + 0AX);
In Josef's example viewtopic.php?f=32&t=208#p1370
there are also the request:

Code: Select all

request := "GET http://greenwoodfarm.com:80/ HTTP/1.0" + CRLF
      + "Host: greenwoodfarm.com" + CRLF
      + CRLF;
which then is sending to server.
User avatar
Ivan Denisov
Posts: 362
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: CommStreams

Post by Ivan Denisov »

Josef Templ wrote:If there are any problems with downloading, it may be required to look into the responses
provided by the http server directly. I don't know if this is possible with Ivan's program.
My example supports redirects and chunked answers. Also support callbacks, what to do with downloaded data.
Снимок экрана от 2018-11-21 09-17-57.png
Снимок экрана от 2018-11-21 09-17-57.png (19.28 KiB) Viewed 10515 times
There is no full support for HTTP 1.1 and no support for SSL, however for most simple cases it is useful :)
User avatar
DGDanforth
Posts: 59
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, CA, U.S.A.
Contact:

Re: CommStreams

Post by DGDanforth »

Ivan Denisov wrote:
Josef Templ wrote:If there are any problems with downloading, it may be required to look into the responses
provided by the http server directly. I don't know if this is possible with Ivan's program.
My example supports redirects and chunked answers. Also support callbacks, what to do with downloaded data.
Снимок экрана от 2018-11-21 09-17-57.png
There is no full support for HTTP 1.1 and no support for SSL, however for most simple cases it is useful :)

Code: Select all

MODULE TestDownLoadAndOpen;

	IMPORT
		CommHttp;
	
	PROCEDURE DownLoadAndOpen (url: ARRAY OF CHAR);
	VAR d: CommHttp.Dowing;
	BEGIN
		d := CommHttp.NewDownLoad(url);
		d.onFinish := OpenAsText; 
		(* d.silent := TRUE; (* to hide log view *) *)
		d.Start;
	END DownLoadAndOpen;

END TestDownLoadAndOpen.

"CommObxHttp.DownLoadAndOpen('http://google.com')"
There is no module called
CommHttp
OR
CommObxHttp
User avatar
DGDanforth
Posts: 59
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, CA, U.S.A.
Contact:

Re: CommStreams

Post by DGDanforth »

Ivan Denisov wrote: I got Josef's example to work viewtopic.php?f=32&t=208#p1370
User avatar
Ivan Denisov
Posts: 362
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: CommStreams

Post by Ivan Denisov »

DGDanforth wrote: There is no module called
CommHttp
OR
CommObxHttp
This modules I packed here :)
viewtopic.php?f=32&t=208#p1363
Post Reply