QB64 Report

Episode 4 - Networking in QB64

July 14, 2020 QB64 Team Season 1 Episode 4
QB64 Report
Episode 4 - Networking in QB64
Chapters
00:00:00
Intro
00:05:29
Sample 1 - downloading from a website
00:09:20
Sample 2 - split request
00:13:53
Sample 3 - simple server
00:21:36
Sample 4 - simple client
00:33:39
Final words
QB64 Report
Episode 4 - Networking in QB64
Jul 14, 2020 Season 1 Episode 4
QB64 Team

In this episode, Fellippe and Dave talk to Luke, one of the developers maintaining QB64, about about TCP/IP communications, how to create a simple server program and a simple client program to connect to it - both locally and over the Internet.

Here are the code snippets explained in this episode:
'-------------------------------
'Sample 1: Simple HTTP request
h& = _OPENCLIENT("tcp/ip:80:alephc.xyz")
s$ = "GET /test.txt HTTP/1.0" + CHR$(13) + CHR$(10) + CHR$(13) + CHR$(10)
PUT #h&, , s$

s$ = ""
WHILE s$ = ""
    GET #h&, , s$
WEND
PRINT s$
CLOSE #h&

'-------------------------------
'Sample 2: Split request
'-------------------------------
h& = _OPENCLIENT("tcp/ip:80:alephc.xyz")
s$ = "GET /test.tx"
PUT #h&, , s$
s$ = "t HTTP/1.0" + CHR$(13) + CHR$(10) + CHR$(13) + CHR$(10)
PUT #h&, , s$

s$ = ""
WHILE s$ = ""
    GET #h&, , s$
WEND
PRINT s$
CLOSE #h&

'-------------------------------
'Sample 3: LONG Doubler
'-------------------------------
host& = _OPENHOST("tcp/ip:9991")
DO
    c& = _OPENCONNECTION(host&)
    IF c& < 0 THEN
        PRINT "Received connection"
        DO
            GET #c&, , value&
        LOOP WHILE EOF(c&)
        PRINT "Received"; value&
        result& = value& * 2
        PUT #c&, , result&
        CLOSE #c&
    END IF
    _LIMIT 10
LOOP
CLOSE host&


'-------------------------------
'Sample 4: LONG Doubler Client
'-------------------------------
    INPUT "Enter value:", value&
    h& = _OPENCLIENT("tcp/ip:9991:localhost")
    PUT #h&, , value&
    DO
        GET #h&, , response&
    LOOP WHILE EOF(h&)
    PRINT "Response is"; response&
    CLOSE h&

Support the show (https://www.patreon.com/qb64)

Show Notes Chapter Markers

In this episode, Fellippe and Dave talk to Luke, one of the developers maintaining QB64, about about TCP/IP communications, how to create a simple server program and a simple client program to connect to it - both locally and over the Internet.

Here are the code snippets explained in this episode:
'-------------------------------
'Sample 1: Simple HTTP request
h& = _OPENCLIENT("tcp/ip:80:alephc.xyz")
s$ = "GET /test.txt HTTP/1.0" + CHR$(13) + CHR$(10) + CHR$(13) + CHR$(10)
PUT #h&, , s$

s$ = ""
WHILE s$ = ""
    GET #h&, , s$
WEND
PRINT s$
CLOSE #h&

'-------------------------------
'Sample 2: Split request
'-------------------------------
h& = _OPENCLIENT("tcp/ip:80:alephc.xyz")
s$ = "GET /test.tx"
PUT #h&, , s$
s$ = "t HTTP/1.0" + CHR$(13) + CHR$(10) + CHR$(13) + CHR$(10)
PUT #h&, , s$

s$ = ""
WHILE s$ = ""
    GET #h&, , s$
WEND
PRINT s$
CLOSE #h&

'-------------------------------
'Sample 3: LONG Doubler
'-------------------------------
host& = _OPENHOST("tcp/ip:9991")
DO
    c& = _OPENCONNECTION(host&)
    IF c& < 0 THEN
        PRINT "Received connection"
        DO
            GET #c&, , value&
        LOOP WHILE EOF(c&)
        PRINT "Received"; value&
        result& = value& * 2
        PUT #c&, , result&
        CLOSE #c&
    END IF
    _LIMIT 10
LOOP
CLOSE host&


'-------------------------------
'Sample 4: LONG Doubler Client
'-------------------------------
    INPUT "Enter value:", value&
    h& = _OPENCLIENT("tcp/ip:9991:localhost")
    PUT #h&, , value&
    DO
        GET #h&, , response&
    LOOP WHILE EOF(h&)
    PRINT "Response is"; response&
    CLOSE h&

Support the show (https://www.patreon.com/qb64)

Sample 1 - downloading from a website
Sample 2 - split request
Sample 3 - simple server
Sample 4 - simple client
Final words