zPocketScript Class Reference: Socket


Prototype: File

Library: libjs_net

The Socket object provides encapsulation of the socket's API.
eg.
var connection=new Socket(Socket.PF_INET,Socket.SOCK_STREAM);

As the prototype chain for Socket objects includes the File object, you can Socket's inherit all methods from the File object. As with a file, a Socket object is closed when you delete it.

eg.
// resolve the address of Craig's website
var serverAddress=new Host("angela1.data-uncertain.co.uk");
if(serverAddress)
{
// got the address - let's create a socket
 s=new Socket(Socket.PF_INET,Socket.SOCK_STREAM);
// now, let's connect the socket to port 80 on Craig's server...
 connected=s.connect(serverAddress,80);
 if(connected)
 {
  // success - let's make an HTTP request
  // - note that writeln() and readString() are inherited from the File object
  s.writeln("GET / HTTP/1.0");
  s.writeln("");
  response=s.readString(10000);
 }else{
  // failure :(
 }
 // all done, delete the socket, so it get's closed
 delete s;
}
delete serverAddress;

NOTE:The Socket object is a seperate plugin library, not part of the core library.

Methods

Properties

Constants