Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [AGK] How to use sockets, client and server

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Nov 2023 23:33
I've never touched the networking commands before, I just learned today it had socket support. Decided to make a demo on how to use them.
This app will work as both server and client, operating on the localhost for simplicity so you don't have to mess with firewall settings or configure port forwarding on your router.

Upon launching the app, the server will start listening for incoming connections.

[keys]
c = connect the client to the server
space = sends a timestamp to the client
s = sends the timestamp back to the server, encoded in both hex and base64
esc = exists the program after closing the sockets


Yes, sockets are limited to only 1400 bytes per packet. This isn't necessarily an AppGameKit limitation, but a rather standard default packet size in most TCP situations. So what happens if you wish to send something larger than 1.4KB? You'd have to send the data in chunks and reassemble it on the receiving end. "Chunking" is a common practice when uploading large files over HTTP as a typical connection will timeout before the data can be sent be. It isn't too difficult to implement, it just requires a few extra steps. I plan to make another demo show how to do that.


Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-11-17 22:24:35
Your offset time is: 2024-11-17 22:24:35