Spherical forums

Sphere Development => Sphere Support => Topic started by: Cape Abel on April 11, 2014, 07:41:33 am

Title: How do you use sockets?
Post by: Cape Abel on April 11, 2014, 07:41:33 am
The wiki isn't very clear. The forum search I did didn't give any clear examples. I tried using them on my own but although I can get .isConnected() to return true, I can't get anything from .read(). Does anyone have any working examples I could look at?
Title: Re: How do you use sockets?
Post by: Flying Jester on April 11, 2014, 01:50:49 pm
The sockets work like actual network sockets. You can see a couple simple examples on archives of the old wiki. (https://web.archive.org/web/20090106030445/http://www.spheredev.org/wiki/OpenAddress)

Can we see what you are trying to do? Using sockets is pretty intermediate programming.

You need to either act like a server and listen on a port, or a client and call connect. In either case, you will need another service running on the other side, trying to do the opposite that you are.

Read() won't, for instance, read websites. You need to do an HTTP request.

The key here is that these are just like full BSD sockets. They don't buy you anything on their own but raw data transfer. You would need to implement whatever protocol you want to use (http, ftp, irc, something custom, something else entirely) on your own.

If you really want to do this, I really, really recommend trying to make something like an IRC client first. IRC is nice because it is a very simple and well documented communication standard, is a pretty good example of how client-server communications work (at least conceptually), and has tangible results.
Title: Re: How do you use sockets?
Post by: Rahkiin on April 14, 2014, 12:30:46 pm
I do like to point out that HTTP is easier than IRC. You just connect, write the HTTP GET header and then read the response :) Just some string processing. But eh. :)

Good luck!