[Jslib] new socket.js

Pete Collins pete at mozdev.org
Tue Sep 30 16:11:53 EDT 2003


> Unless somebody objects, I guess I'll be working out with Pete how to 
> commit this new version.

Just file a new bug w/ the patch and/or new file and I'll check it in.

Thanks

--pete


> 
> thank you for your time.
> 
> I Issues:
> As usual, there are some issues:
> 1) the interfaces are not the same as the original.  Since the original 
> didn't work (therefore,
> nobody was using it), I don't think that will be much of a problem.  
> However, the new interfaces are
>  more tuned to where I was going (which might not be acceptable to 
> everybody...anybody?).  More on
> this later.
> 
> 2) My changes do not currently support asynchronous communication.  Not 
> that I have anything against
> it, but my application doesn't do that so it's difficult to develop/test 
> against.  Suggestions are
> welcome.
> 
> II Socket interfaces:
>                 returns
> Socket( [class_id] )        n/a        : constructor
>                         : class_id(String) => class identifier (optional)
> 
> By default, Socket uses the result of Component.classes[
> "@mozilla.org/network/socket-transport-service;1" ] for creating a 
> socket service.
> 
> If the argument "class_id" is given then the results of 
> Component.classesByID[ class_id ] is used
> for creating a socket service.
> 
> open( host, port, [binary] )    true        : opens socket
>                         : host(String) => tcp/ip address
>                         : port(Number) => socket port
>                         : binary(Boolean) => if true then binary comm 
> (optional)
> 
> By default, open(...) creates a scriptable input-stream.
> If the argument "binary" is 'false' then a binary input-stream will be 
> used.
> 
> close()                nothing        : closes socket
> 
> write( String )            true on success    : writes data to socket
>                         : String => data to write out
> Failure on write will cause an exception to be thrown (actually passing 
> along the exception thrown
> by the socket call).  If an exception is thrown than the Socket will no 
> longer believe it is
> connected (altho, close() should probably still be invoked).
> 
> read( Number )            String        : reads data from socket
>                         : Number => number of bytes to read
> Attempts to read more bytes than exists on the port are trimmed to the 
> actual bytes available.
> Other failures will cause an exception to be thrown (passed along).  If 
> an exception is thrown than
> the Socket will no longer believe it is connected (altho, close() should 
> probably still be invoked).
> 
> available()            Number        : bytes waiting on socket
> 
> If the connection was not actually made (open() really failed) or was 
> lost then an exception will be
> thrown.
> 
> III Attributes
> 
> All of these attributes are used by open(), so they should be tweaked 
> for your application somewhere
> between "foo = new Socket" and "foo.open()"
> 
> 1)  nsISocketTransport.openInputStream arguments:
>     openInputFlags = 0;                  open flags
>     openInputSegmentSize = 0;            segmentSize
>     openInputSegmentCount = 0;           segmentCount
> 
> 2)  nsISocketTransport.openOutputStream arguments:   
>     openOutputFlags = 0;                 open flags   
>     openOutputSegmentSize = 0;           segmentSize
>     openOutputSegmentCount = 0;          segmentCount
> 


-- 
Pete Collins
www.mozdev.org
www.mozdevgroup.com




More information about the Jslib mailing list