PDA

View Full Version : ThinBasic online help's TCP example



DirectuX
24-10-2018, 19:02
Hi,

adapting this example: https://www.thinbasic.com/public/products/thinBasic/help/html/index.html?tcp_example1.htm because it is not working for me as-is;





'---Load Console Module
Uses "Console"


'--------------------------------------------------------------------------------

' - connect to a web site

' - ask for a page

' - save it into a buffer

' - save the buffer into a text file

'--------------------------------------------------------------------------------


'---Load TCP module

USES "TCPUDP"


'---Load File module

USES "FILE"

'---Define some global variables and init them

Dim MyPage As String = "https://www.thinbasic.com/index.php"'"http://www.thinbasic.com/index.php"
Dim MySite As String = "www.thinbasic.com"



Dim sBuffer As String
Dim sPage As String
Dim Count As Long

'---Get a file number

Dim nFile As Long = Tcp_FreeFile

'---Open a connection

TCP_Open(443, MySite, nFile) ' <-- *** here 80 or 443 ***

'---Send request

TCP_Print(nFile, "GET " & MyPage)' & " HTTPS/1.0")
TCP_Print(nFile, "HOST: " & MySite)
TCP_Print(nFile, "User-Agent: TCP Test using thinBasic")
TCP_Print(nFile, "")


'---Get back data in a loop

Do

INCR Count

sBuffer = TCP_Recv(nFile, 4096)
sPage = sPage & sBuffer

Loop While ((Len(sBuffer) > 0) And (ERR = 0))



'---Close the channel

TCP_Close(nFile)

'---Save the page

File_Save(APP_SourcePath & "Page.txt", sPage)



PrintL "Press a key to end program"

'---Wait for a key press
WaitKey




Have you the same issue ?

I can't get it work with https port 443 (see https://www.thinbasic.com/public/products/thinBasic/help/html/index.html?tcp_open.htm)


Does it mean that accepted values are just the four mentioned aka either 80, 25, "HTTP", or "SMTP" ?
Is using INet the only alternative ?

ErosOlmi
24-10-2018, 22:02
Maybe my example was a bit old and confusing.
I will try to make a better one.

TCP/UDP module works on the transport layer (layer 4) of the OSI Model: https://en.wikipedia.org/wiki/OSI_model

That module doesn't know anything about transported data, it is just responsible of transporting and re-organizing bytes.
So HTTP, SMTP, FTP ... are just ports to connect to.
Successive layers of the OSI model are responsible to give a meaning to transported data.

If you tell me what you are trying to do, maybe I get help on that.

Ciao
Eros