Skip to main content

News

Topic: How do you use sockets? (Read 4020 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
How do you use sockets?
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?

Re: How do you use sockets?
Reply #1
The sockets work like actual network sockets. You can see a couple simple examples on archives of the old wiki.

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.
  • Last Edit: April 11, 2014, 07:31:04 pm by Flying Jester

  • Rahkiin
  • [*][*][*]
Re: How do you use sockets?
Reply #2
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!