Author Topic: Scriptbasic: SOCK module  (Read 384 times)

Offline AIR

  • BASIC Developer
  • Posts: 741
Scriptbasic: SOCK module
« on: March 31, 2019, 07:27:18 PM »
I started writing this because the default SOCKET interface doesn't support UDP, etc.

Also, the old ssocket module has some weird stuff going on in it.

Not finished yet, but here is an example:

Code: Script BASIC
  1. import sock.bas
  2.  
  3. ' CREATE NEW **UDP** CONNECTION
  4. conn = SOCK::NEW(SOCK::AF_INET, SOCK::SOCK_DGRAM, SOCK::IPPROTO_IP)
  5.  
  6. ' SET THE SOCKET CONNECTION PARAMETERS
  7. ' SERVER, CONNECTION TYPE, PORT
  8. ' FOR RETRIEVING LOCAL IP NON-EXISTANT SERVER IS OKAY
  9. SOCK::SET("1.0.0.0",SOCK::AF_INET,1)
  10.  
  11. ' CONNECT
  12. SOCK::CONNECT(conn)
  13.  
  14. ' RETRIEVE IP OF **DEFAULT** ADAPTER
  15. ' DOESN'T MATTER IF IT IS ETHERNET OR WIFI
  16. ' THE IP OF THE DEFAULT ADAPTER IS RETURNED
  17. print "Active IP: ",SOCK::GETIP(conn),"\n"
  18.  

riveraa@dpi:~/Projects/sb $ ./sb.AppImage socktest.bas
Active IP: 192.168.1.64


For most cases, the built-in SOCKET should suffice, this is more for those instances when you need more configuration options (like UDP support).
 
AIR.

Offline John

  • Forum Support / SB Dev
  • Posts: 2879
    • ScriptBasic Open Source Project
Re: Scriptbasic: SOCK module
« Reply #1 on: March 31, 2019, 07:33:17 PM »
A major isssue with the built in socket support is there is no timeout and will hang the connection.