TCP/IP calls from Win32Forth??? 
Author Message
 TCP/IP calls from Win32Forth???

Has anyone done this?  I'm thinking of writing a simple
application that can download and manipulate HTML
files.  (Similair to some Rebol ideas)  At first step I
mainly want to just be able to connect to the web
server and download the file from within Forth.


Mon, 12 Nov 2001 03:00:00 GMT  
 TCP/IP calls from Win32Forth???
John,

I have made just experimentations in this domain, with SwiftForth, and used
with some success the following WININET.DLL functions set.

I hope this can help you.

DLL: WININET
-------------
FUNC: InternetOpen  ( lpszAgent dwAccessType lpszProxyName lpszProxyBypass
dwFlags -- hInet )
FUNC: InternetCloseHandle ( hInet -- bool )
FUNC: InternetConnect ( hInet szHost nServerPort szUser  szPass dwService
dwFlags 0 -- hFtp )
FUNC: FtpGetCurrentDirectory ( hFtpSession lpszCurrentDirectory
lpdwCurrentDirectory -- flag )
FUNC: FtpSetCurrentDirectory ( hConnect pszDir -- flag )
FUNC: InternetGetLastResponseInfo ( lpdwError lpszBuffer lpdwBufferLength
-- flag )

Regards
Charles Melice



Quote:
> Has anyone done this?  I'm thinking of writing a simple
> application that can download and manipulate HTML
> files.  (Similair to some Rebol ideas)  At first step I
> mainly want to just be able to connect to the web
> server and download the file from within Forth.



Tue, 13 Nov 2001 03:00:00 GMT  
 TCP/IP calls from Win32Forth???

Quote:

> John,

> I have made just experimentations in this domain, with SwiftForth, and used
> with some success the following WININET.DLL functions set.

> I hope this can help you.

> DLL: WININET
> -------------
> FUNC: InternetOpen  ( lpszAgent dwAccessType lpszProxyName lpszProxyBypass
> dwFlags -- hInet )
> FUNC: InternetCloseHandle ( hInet -- bool )
> FUNC: InternetConnect ( hInet szHost nServerPort szUser  szPass dwService
> dwFlags 0 -- hFtp )
> FUNC: FtpGetCurrentDirectory ( hFtpSession lpszCurrentDirectory
> lpdwCurrentDirectory -- flag )
> FUNC: FtpSetCurrentDirectory ( hConnect pszDir -- flag )
> FUNC: InternetGetLastResponseInfo ( lpdwError lpszBuffer lpdwBufferLength
> -- flag )

> Regards
> Charles Melice

Thanks!  I remember Elizabeth had said how easy it is to use DLL's from within
SwiftForth.  (I now wish I had tried that function when I had my evaluation
copy.)

So can anyone tell me how to set up DLL calls in Win32Forth?



Tue, 13 Nov 2001 03:00:00 GMT  
 TCP/IP calls from Win32Forth???
To define a dll in Win32Forth:

WinLibrary WININET.DLL

Since functions are automatically defined the first time you use them, you
just need to do this:

: someword
    dwFlags lpszProxyBypass lpszProxyName dsAccessType plszAgent
    call InternetOpen ;

Remember in Win32Forth the arguments are in the reverse order from the Win32
documentation. Also you must do a rel>abs to convert any addresses from
Win32Forth releative addresses to Windows absolute addresses.

Tom Zimmer has made changes to WinView to allow it to access HTML pages on
an internet server. This code hasn't been released yet but should be in the
next version.

Andrew

Quote:


>> John,

>> I have made just experimentations in this domain, with SwiftForth, and
used
>> with some success the following WININET.DLL functions set.

>> I hope this can help you.

>> DLL: WININET
>> -------------
>> FUNC: InternetOpen  ( lpszAgent dwAccessType lpszProxyName
lpszProxyBypass
>> dwFlags -- hInet )
>> FUNC: InternetCloseHandle ( hInet -- bool )
>> FUNC: InternetConnect ( hInet szHost nServerPort szUser  szPass dwService
>> dwFlags 0 -- hFtp )
>> FUNC: FtpGetCurrentDirectory ( hFtpSession lpszCurrentDirectory
>> lpdwCurrentDirectory -- flag )
>> FUNC: FtpSetCurrentDirectory ( hConnect pszDir -- flag )
>> FUNC: InternetGetLastResponseInfo ( lpdwError lpszBuffer lpdwBufferLength
>> -- flag )

>> Regards
>> Charles Melice

>Thanks!  I remember Elizabeth had said how easy it is to use DLL's from
within
>SwiftForth.  (I now wish I had tried that function when I had my evaluation
>copy.)

>So can anyone tell me how to set up DLL calls in Win32Forth?



Tue, 13 Nov 2001 03:00:00 GMT  
 TCP/IP calls from Win32Forth???

Quote:

> To define a dll in Win32Forth:

> WinLibrary WININET.DLL

> Since functions are automatically defined the first time you use them, you
> just need to do this:

> : someword
>     dwFlags lpszProxyBypass lpszProxyName dsAccessType plszAgent
>     call InternetOpen ;

> Remember in Win32Forth the arguments are in the reverse order from the Win32
> documentation. Also you must do a rel>abs to convert any addresses from
> Win32Forth releative addresses to Windows absolute addresses.

> Tom Zimmer has made changes to WinView to allow it to access HTML pages on
> an internet server. This code hasn't been released yet but should be in the
> next version.

> Andrew

And here following is the extract from WinView that supports opening HTML files
directly off th web.  Web pages are read into local temporary files and viewed
in browse mode.
The constants are just extra ones needed that aren't in WINCON.DLL.

This code is obviously very specific to Win32forth, but might be interesting
reading
for anyone wishing to duplicate the functionality in their own Forth.

The "L" words like LCOUNT, LPLACE and LMAXSTRING just related to CELL counted
strings that have a 1024 byte maximum size.

For those of you with access to my iMacFloppy.com site, the version of
Win32Forth
that contains this code is up there.

Tom Zimmer

P.S.  This code was extracted directly from WinView, and so there re no doubt
some
unresolved external references.  It will not load directly on any previous
version of Win32Forth.

------------[example code from WinView]------------

: "skip-URLbase" ( a1 n1 --- a2 n2 )    \ return a2 and count=n2 of URL after
base
                                        \ scan past "HTTP://" to last '/' in URL

                s" //" search IF 2 /string THEN
                [char] / scan dup
                IF      1 /string
                        BEGIN   2dup [char] / scan ?dup
                        WHILE   2swap 2drop 1 /string
                        REPEAT  drop
                THEN    ;

: "URL-base"    ( a1 n1 -- a2 n2 )      \ return URL base
                2dup "skip-URLbase" nip - ;

LMAXSTRING Pointer URLcombined

: "build-URL"   { relURL relLen -- adr2 len2 }
                URL$    LCOUNT "URL-base"       URLcombined  LPLACE

ends in a '\'
                IF      [char] / URLcombined C+LPLACE
                THEN

+LPLACE
                URLcombined +LNULL
                URLcombined LCOUNT ;

#define INTERNET_OPEN_TYPE_PRECONFIG    0   // use registry configuration
#define INTERNET_OPEN_TYPE_DIRECT       1   // direct to net
#define INTERNET_OPEN_TYPE_PROXY        3   // via named proxy

#define INTERNET_FLAG_NO_CACHE_WRITE    0x04000000  // don't write this item to
the cache
#define INTERNET_FLAG_DONT_CACHE        INTERNET_FLAG_NO_CACHE_WRITE
#define INTERNET_FLAG_MAKE_PERSISTENT   0x02000000  // make this item persistent
in cache
#define INTERNET_FLAG_OFFLINE           0x01000000  // use offline semantics

0 value HAVEInternet?
0 value HINTERNETSESSION
0 value HINTERNETURL

: html-release  ( -- )                  \ release the session handle
                HINTERNETSESSION Call InternetCloseHandle drop
                NULL to HINTERNETSESSION ;

UNLOAD-CHAIN CHAIN-ADD-BEFORE html-release       \ add to termination chain

VARIABLE NumberOfBytesRead
4000     CONSTANT HTMLSIZE
HTMLSIZE Pointer  HtmlBuf
0        value    HTMLcnt

: "HTML         { htmlAdr HtmlLen \ open$ html$ name$ fhndl -- }
                max-path   LocalAlloc: open$
                LMAXSTRING LocalAlloc: html$
                MAXSTRING  LocalAlloc: name$
                htmlAdr HtmlLen html$ LPLACE
                                html$ +LNULL
                >E-unminimize
                ?save-new                       ?EXIT
                HAVEInternet? 0=
                IF      s" Interogating Internet..." "message
                        0 Call InternetAttemptConnect dup 0= to HAVEInternet?
                        IF      beep message-off EXIT
                        THEN
                THEN
                HINTERNETSESSION 0=
                IF      s" Opening Connection..." "message
                        NULL
                        NULL
                        NULL
                        INTERNET_OPEN_TYPE_DIRECT
                        z" WinView" rel>abs
                        Call InternetOpen dup to HINTERNETSESSION 0=
                        IF      beep message-off EXIT
                        THEN
                THEN
                s" Opening URL..." "message
                0                                               \ dwContext
                INTERNET_FLAG_DONT_CACHE                        \ dwFlags
                s" Accept: */*\n\n" swap        rel>abs         \
dwHeadersLength, lpszHeader
                html$ LCOUNT DROP rel>abs                       \ lpszUrl
                HINTERNETSESSION                                \
hInternetSession
                Call InternetOpenUrl dup to HINTERNETURL
                IF      s" WinView."          name$  place
                        HTMLcnt 0 <# # # # #> name$ +place
                        1 +to HTMLcnt
                        name$ count       delete-file drop
                        name$ count   r/w create-file 0=
                        IF      to fhndl
                                s" Reading URL..." "message
                                BEGIN   NumberOfBytesRead       rel>abs
                                        HTMLSIZE
                                        HtmlBuf                 rel>abs
                                        HINTERNETURL
                                        Call InternetReadFile >r

write-file drop
                                        r> 0<>                          \ read
succeeded

more bytes to read
                                UNTIL
                                fhndl close-file drop
                                name$ count "+open-text
                                FALSE to browse?
                                browse-toggle
                                TRUE to from-web?                       \ mark
as from the Web
                                html$ LCOUNT URL$ LPLACE                \ save
the URL
                                             URL$ +LNULL
                        ELSE    beep
                        THEN
                        HINTERNETURL Call InternetCloseHandle drop
                        NULL to HINTERNETURL
                ELSE    beep
                THEN
                message-off
                SetFocus: EditWindow
                RefreshAll: EditWindow
                ReTitle: WinViewWindow ;



Wed, 14 Nov 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Want TCP/IP transfer using Win32forth

2. Calling TCP/IP from MF

3. does anyone have an example of a c++ TCP/IP client that works with labview TCP?IP server ??

4. How do I use dial up (PPP) TCP/IP port on a machine which also has TCP/IP LAN

5. TCP/IP for Smalltalk V

6. Interface Woes...Emulator/TCP/IP or GDDM?

7. TCP/IP AbtSocket connection problems

8. TCP/IP Under MVS: Assembler Interface

9. US - SE FL-***SMALLTALK/C++PROGRAMMER (DB2,MVS/TSO,AIX,TCP/IP)***-CONTRACT

10. TCP/IP, TN3270 & APL/370

11. APL communications via TCP/IP or DDE

12. VW 2.5 - TCP/IP on MS Windows

 

 
Powered by phpBB® Forum Software