||6 months ago|
|bin||6 months ago|
|examples||6 months ago|
|icons||6 months ago|
|src||6 months ago|
|.gitignore||6 months ago|
|AMOSPro_BSDSocket.Lib||6 months ago|
|API.md||6 months ago|
|LICENSE||6 months ago|
|README.md||6 months ago|
|aminet.readme.erb||6 months ago|
|icons.info||6 months ago|
AMOS Professional BSD Socket Extension
Want to get online with your AMOS Professional program? Now you can in style!
This extension provides a wrapper around the BSD Socket library provided by your Internet stack for use with AMOS Professional. There's some attempt to roll up some of the low-level functionality into something more usable by AMOS.
- Within AMOS Professional:
Config -> Set Interpreter
Load Default Configuration
Set Loaded Extensions
Extension Slot 18 --
Restart AMOS Professional
Type in the following and Run:
Print Socket Library Open
The line should tokenize, and running it should print -1 if you have no Internet stack running, or a large number if you do.
Communicating with an HTTP server
LIB=Socket Library Open If LIB<=0 End End If SOCKET=Socket Create Inet Socket _=Socket Set Nonblocking(SOCKET,True) ' connect to aminet.net IP$=Dns Get Address By Name$("aminet.net") ALREADY_CONNECTED=Socket Connect(SOCKET To IP$,80) Reserve As Work 30,1024 For I=1 To 100 If ALREADY_CONNECTED=-1 RESULT=Socket Wait Async Writing(SOCKET,100) If RESULT=-3 Print "Socket connect failure!" Exit End If If RESULT>0 ALREADY_CONNECTED=0 End If End If If ALREADY_CONNECTED=0 HTTPGET$="GET / HTTP/1.0"+Chr$(10)+"Host: amiga"+Chr$(10)+Chr$(10) Print "Making HTTP request to aminet.net" _=Socket Send(SOCKET,Varptr(HTTPGET$),Len(HTTPGET$)) For J=1 To 100 RESULT=Socket Wait Async Reading(SOCKET,5000) If RESULT>0 OUT=Socket Recv(SOCKET To Start(30),1024) _DATA$="" For K=0 To OUT-1 _DATA$=_DATA$+Chr$(Peek(Start(30)+K)) Next K Print _DATA$ If OUT<1024 Exit 2 End If End If Next J Exit End If Next I Socket Library Close
Starting a server
If Socket Library Open<=0 End End If SOCKET=Socket Create Inet Socket _=Socket Set Nonblocking(SOCKET,True) _=Socket Reuse Addr(SOCKET) RESULT=Socket Bind(SOCKET To "INADDR_ANY",8000) _=Socket Listen(SOCKET) Print "listening on port 8000" For I=1 To 100 RESULT=Socket Wait Async Reading(SOCKET,500) If RESULT>0 _REMOTE_SOCKET=Socket Accept(SOCKET) Print Socket Inet Ntoa$(Socket Get Host(_REMOTE_SOCKET)) Print Socket Get Port(_REMOTE_SOCKET) Print Socket Recv$(_REMOTE_SOCKET,1024) Exit End If Wait Vbl Next I Socket Library Close
Who's using the extension?
- As of April 2023, the extension's been in heavy use for over a month on the client side of the game.
Doing something cool with the extension? Contact me and I'll add it to the list!
- The BSD Socket library, and all sockets, will close automatically when the program runs again. Sockets will stay open after stopping you code so you can debug issues from the AMOS console.
- Since AMOS takes over Ctrl-C handling, you have to continually
poll for socket statuses on nonblocking sockets. Trying to use
a blocking socket will likely cause AMOS to hang indefinitely!
- Using the Wait Async functions with small timeouts are the most system-friendly way of doing this.
- MiamiDX can be fiddly, at least it is on my MiSTer set up. If Internet connectivity is not working, try re-connecting to the network.
- If using Roadshow,
bsdsocket.librarywill always be available, so you can't use its presence or lack thereof to test if Internet is available. You'll have to use a combination of DNS lookups and/or connection timeouts using
Socket Async Wait Writingto determine if the Internet is available.
This project uses semantic versioning.
- If the major number increases, API has changed.
- Otherwise, the extension's API should be backwards compatible.
Copyright 2023 John Bintz. Licensed under the MIT License.
If you use this in your project, and you really want to, throw a link to theindustriousrabbit.com somewhere! You can also find a donate link on the About section on The Industrious Rabbit.
Feedback? Bug reports?
Go to the About section on The Industrious Rabbit to contact me.
- First public release
- Fix bug in Socket Wait Async Writing where result of getsockopt was incorrectly used.
- Clone the AMOS Professional source code
- Note that you'll have to fix up some assigns and files in the AMOS Professional source directory. I'll update this README with those changes once I track them down...
jlha-utilsand a modern enough Java to run it
- Install Ruby