set display mode 800, 600, 32
set window on
dim args() as string
args$ = CL$()
if args$ > ""
array insert at bottom args()
args() = first token$(args$, " ")
repeat
a$ = next token$(" ")
if a$ > ""
array insert at bottom args()
args() = a$
endif
until a$ = ""
endif
hSocket = new udp socket()
if hSocket > 0
if args(0) = "-s"
didBind = bind socket(hSocket, intval(args(1)))
if didBind
print "UDP Socket bound to port " + args(1)
else
print "Failed to bind socket"
endif
else
didConnect = connect socket(hSocket, hostname to ip(args(0)), intval(args(1)))
if didConnect
print "UDP Socket connected to " + args(0) + ":" + args(1)
res = send socket string(hSocket, "Hello from new connection")
else
print "failed to connect"
endif
endif
endif
do
if socket poll read(hSocket) = 1
msg$ = recv socket string$(hSocket)
if msg$ <> ""
print msg$
endif
endif
loop
compile then run from the command line as shown here.
-s [portnumber] will set up the server host
[ip] [portnumber] will set up a client.
only run 1 instance with -s run as many client instances as you want.
This uses Matrix1 sockets, this is UDP, but TCP works similarly.

http://games.joshkirklin.com/sulium
A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.