Normal Topic Its the weekend, but... (Read 344 times)
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Its the weekend, but...
Dec 10th, 2005 at 6:48pm
Print Post Print Post  
Well, I got the networking commands into SBasic for 2.0. So far, only the necessities:
Code
Select All
@OpenNetworkConnection(serverName as string, port as int) as int // returns the netID
CloseNetworkConnection(netID as int)
NetworkWrite(netID as int, str as string)
@NetworkRead(netID as int, lengthLimit as int) as string
 



For example, here is the SBasic code needed to read my web page, using the HTTP protocol:
Code
Select All
var net_id as int
var str as string

net_id = @OpenNetworkConnection("www.HammerVE.com", 80)
if(net_id > -1)
{
	  NetworkWrite(net_id, "GET /index.html HTTP/1.0")
	  NetworkWrite(net_id, @NewLine())
	  NetworkWrite(net_id, @NewLine())

	  str = @NetworkRead(net_id, 10000)
	  writeln(str)
	  CloseNetworkConnection(net_id)
}
 



This could be used to read/write any of the internet protocols (HTTP, FTP, NNTP, SMTP, POP, IMAP, etc...). A really clever programmer could even use this to turn a SBasic program into a Sesame client.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Its the weekend, but...
Reply #1 - Dec 10th, 2005 at 7:09pm
Print Post Print Post  
I just gave the @NetworkRead command a third argument: a timeout - so if things don't go as you planned...

I also just added @AcceptNetworkConnection, so if you want to act as a server for other clients you can.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged