structResponse
struct Response
status: int
text: string
error: string
endnet: web requests over HTTP and HTTPS, with WinHTTP. use "net.jamo"
A request waits until the answer has come, or the time runs out. Problems along the way, like a server that can't be reached or takes too long, don't stop the program: the response's error says what went wrong, and its status is 0. Only mistakes in the program itself, like a web address that isn't one, stop it.
Background requests don't wait: start_get and start_post give back a Request at once, and done() checks on it each frame. WinHTTP tells us about progress by calling net_signal on its own threads, so that function only writes numbers into the request's block, which is memory from LocalAlloc that the memory cleaner never sees. Everything else happens on the program's own thread, in done(). A block is only given back once WinHTTP says the request's handle is closed, since it may still write there until then. The block: sent at 0, headers at 4, data waiting at 8 with how much at 12, read done at 16, failed at 20 with the error at 24, closed at 28. The 64 KB from 64 take each piece of the answer, and what's sent with a post follows at 65600. After that come the server name, the method, the path and the headers as Windows text, since WinHTTP may read them after the call that took them has returned.
Links are TCP connections between programs, for multiplayer games. One program listens on a port and others connect to it. Each send() is one whole message: it goes out with its length in front, as 4 bytes, so messages() gives back exactly what was sent, however TCP splits it up on the way. Sockets never wait: messages() sends what's waiting to go and reads what has come, once a frame.
struct Response
status: int
text: string
error: string
endstruct Net
agent: int
session: int
background: int
closing: [int]
seconds: float
sockets_started: bool
open: bool
endstruct Listener
socket: int
port: int
open: bool
endA program waiting for others to connect, on one port
struct Link
socket: int
connecting: bool
open: bool
error: string
outgoing: int
out_size: int
out_start: int
out_used: int
incoming: int
in_size: int
in_used: int
piece: int
endA connection to another program. messages() gives back what came, a whole message at a time
struct Request
net: Net
block: int
connection: int
request: int
stage: int
status: int
buffer: int
capacity: int
used: int
waiting: int
address: NetAddress
result: Response
deadline: float
clock: int
finished: bool
endA request running in the background. Check done() each frame, then read response()
struct NetAddress
secure: bool
host: string
port: int
path: string
endfunc start_net(): Net
func Net.set_timeout(seconds: float)
How long a request may take at each stage before it gives up with a timeout error
func Net.must_be_open()
func Net.close()
func Net.get(url: string): Response
func Net.post(url: string, text: string): Response
Sends text to a web address, as plain UTF-8 text
func Net.request(verb: string, url: string, body: string): Response
func net_time_limits(request: int, seconds: float)
Sets every time limit on one request, including the wait for the answer's headers, which WinHttpSetTimeouts leaves at 90 seconds
func net_failed(code: int, address: NetAddress): Response
func net_address(url: string): NetAddress
func net_starts(text: string, front: string): bool
func Net.start_get(url: string): Request
func Net.start_post(url: string, text: string): Request
func Net.start(verb: string, url: string, body: string): Request
func Request.done(): bool
Takes the request's next steps, and answers true once it has finished, worked or not
func net_clock(place: int): float
Seconds on the PC's steady clock. WinHTTP's own time limits only get checked when something arrives, so each request keeps its own deadline instead
func Request.ask_for_data()
func Request.keep(from: int, count: int)
Copies a piece of the answer out of the block, into memory that grows
func Request.response(): Response
What came back. Only after done() has answered true
func Request.cancel()
Stops a request that isn't needed any more
func Request.fail_with(code: int)
func Request.finish(result: Response)
func Net.tidy()
Gives back the blocks of requests whose handles WinHTTP has finished closing
func Net.closing_count(): int
How many finished requests WinHTTP is still closing
func net_signal(handle: int, block: int, status: int, info: int): int
WinHTTP calls this on its own threads. It only writes numbers into the request's block: it must never make text, arrays or structs, because the memory cleaner works on the program's own thread
func Net.start_sockets()
func Net.listen(port: int): Listener
Waits for other programs to connect on a port, from any PC that can reach this one. Windows may ask whether to let the program through its firewall
func Net.listen_here(port: int): Listener
The same, but only programs on this PC can connect. Good for testing
func Net.listen_on(port: int, address: int): Listener
func Listener.new_links(): [Link]
The links of programs that connected since the last call. Call it once a frame
func Listener.close()
func Net.connect(host: string, port: int): Link
Connects to a program listening on a port. host is an address like "127.0.0.1", or "localhost". The link starts out connecting: check connected(), or just send, since messages wait until it's ready
func net_link(s: int, connecting: bool): Link
func net_new_socket(): int
func net_no_waiting(s: int)
Sockets that never wait
func net_socket_address(address: int, port: int): int
A sockaddr_in: the family, the port with its high byte first, then the address
func net_ipv4(host: string): int
Turns "1.2.3.4" or "localhost" into the 4 bytes an address takes, first number lowest
func Link.connected(): bool
True once the link has finished connecting
func Link.check_connecting()
func Link.send(text: string)
Sends one message. It goes out as soon as it can, during messages()
func Link.make_room(extra: int)
func Link.flush()
Sends as much of what's waiting as the connection takes now, up to 64 KB at a time
func Link.messages(): [string]
Sends what's waiting, reads what has come, and gives back the whole messages. Call it once a frame
func Link.keep_incoming(count: int)
func Link.take_messages(found: [string])
Moves every whole message from what has come into found
func Link.problem(): string
Why the link stopped, or "" while it works
func Link.is_open(): bool
func Link.broken(why: string)
func Link.close()
func net_copy_wide(place: int, text: string): int
Copies text as Windows text, ending in a 0, to a place outside Jamo's memory. Gives back the bytes used
func net_lasting_wide(text: string): int
Windows text that stays put until it's given back with LocalFree