QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: FellippeHeitor on July 14, 2020, 12:48:06 am

Title: QB64 REPORT S01E04: "Networking in QB64"
Post by: FellippeHeitor on July 14, 2020, 12:48:06 am
 [ This attachment cannot be displayed inline in 'Print Page' view ]  

This is the discussion thread for Episode 4 of QB64 Report, which is now available.

🔊 This time we talk to @luke, who's one of QB64's developers, and learn a lot about TCP/IP communications and networking in QB64.

Check it out at http://podcast.qb64.org (http://podcast.qb64.org) and also in all major podcast providers.

I'll share the YouTube version here soon.
Title: Re: QB64 REPORT S01E04: "Networking in QB64"
Post by: FellippeHeitor on July 14, 2020, 12:55:53 am
These are the samples discussed in the episode:

Code: QB64: [Select]
  1. '-------------------------------
  2. 'Sample 1: Simple HTTP request
  3. h& = _OPENCLIENT("tcp/ip:80:alephc.xyz")
  4. s$ = "GET /test.txt HTTP/1.0" + CHR$(13) + CHR$(10) + CHR$(13) + CHR$(10)
  5. PUT #h&, , s$
  6.  
  7. s$ = ""
  8. WHILE s$ = ""
  9.     GET #h&, , s$
  10. CLOSE #h&

Code: QB64: [Select]
  1. '-------------------------------
  2. 'Sample 2: Split request
  3. '-------------------------------
  4. h& = _OPENCLIENT("tcp/ip:80:alephc.xyz")
  5. s$ = "GET /test.tx"
  6. PUT #h&, , s$
  7. s$ = "t HTTP/1.0" + CHR$(13) + CHR$(10) + CHR$(13) + CHR$(10)
  8. PUT #h&, , s$
  9.  
  10. s$ = ""
  11. WHILE s$ = ""
  12.     GET #h&, , s$
  13. CLOSE #h&

Code: QB64: [Select]
  1. '-------------------------------
  2. 'Sample 3: LONG Doubler
  3. '-------------------------------
  4. host& = _OPENHOST("tcp/ip:9991")
  5.     c& = _OPENCONNECTION(host&)
  6.     IF c& < 0 THEN
  7.         PRINT "Received connection"
  8.         DO
  9.             GET #c&, , value&
  10.         LOOP WHILE EOF(c&)
  11.         PRINT "Received"; value&
  12.         result& = value& * 2
  13.         PUT #c&, , result&
  14.         CLOSE #c&
  15.     END IF
  16.     _LIMIT 10
  17. CLOSE host&

Code: QB64: [Select]
  1. '-------------------------------
  2. 'Sample 4: LONG Doubler Client
  3. '-------------------------------
  4.     INPUT "Enter value:", value&
  5.     h& = _OPENCLIENT("tcp/ip:9991:localhost")
  6.     PUT #h&, , value&
  7.     DO
  8.         GET #h&, , response&
  9.     LOOP WHILE EOF(h&)
  10.     PRINT "Response is"; response&
  11.     CLOSE h&
Title: Re: QB64 REPORT S01E04: "Networking in QB64"
Post by: Ashish on July 14, 2020, 01:47:32 am
Great! :)
Title: Re: QB64 REPORT S01E04: "Networking in QB64"
Post by: Qwerkey on July 14, 2020, 04:46:30 am
@luke definitely gets the Tim Berners-Lee award.  It is amazing that QB64 can do all that stuff.  (It's all a bit beyond my skill level, I think that I'll be sticking with _MAPTRIANGLE).
Title: Re: QB64 REPORT S01E04: "Networking in QB64"
Post by: FellippeHeitor on July 14, 2020, 05:41:43 am
Here's the YouTube version: