api/sys/net/socket [en]
Differences between version EMPTY and #13539
0a1,123
> [api]
>
> [name][kwd]class[/kwd] sys.net.Socket[/name]
> [pf]Available in neko, php, cpp[/pf]
> [doc]
> A TCP socket class : allow you to both connect to a given server and exchange messages or start your own server and wait for connections.
> [/doc]
>
> [field][kwd]var[/kwd] custom : [[/api/Dynamic]]
> [doc _custom]
> A custom value that can be associated with the socket. Can be used to retreive your custom infos after a ''select''.
> [/doc _custom]
> [/field]
>
> [field][kwd]var[/kwd] input(default,null) : [[/api/haxe/io/Input]]
> [doc _input]
> The stream on which you can read available data. By default the stream is blocking until the requested data is available, use ''setBlocking(false)'' or ''setTimeout'' to prevent infinite waiting.
> [/doc _input]
> [/field]
>
> [field][kwd]var[/kwd] output(default,null) : [[/api/haxe/io/Output]]
> [doc _output]
> The stream on which you can send data. Please note that in case the output buffer you will block while writing the data, use ''setBlocking(false)'' or ''setTimeout'' to prevent that.
> [/doc _output]
> [/field]
>
> [field][kwd]function[/kwd] new() : [[/api/Void]]
> [doc _new]
> Creates a new unconnected socket.
> [/doc _new]
> [/field]
>
> [field][kwd]function[/kwd] accept() : [[/api/sys/net/Socket]]
> [doc _accept]
> Accept a new connected client. This will return a connected socket on which you can read/write some data.
> [/doc _accept]
> [/field]
>
> [field][kwd]function[/kwd] bind( host : [[/api/sys/net/Host]], port : [[/api/Int]] ) : [[/api/Void]]
> [doc _bind]
> Bind the socket to the given host/port so it can afterwards listen for connections there.
> [/doc _bind]
> [/field]
>
> [field][kwd]function[/kwd] close() : [[/api/Void]]
> [doc _close]
> Closes the socket : make sure to properly close all your sockets or you will crash when you run out of file descriptors.
> [/doc _close]
> [/field]
>
> [field][kwd]function[/kwd] connect( host : [[/api/sys/net/Host]], port : [[/api/Int]] ) : [[/api/Void]]
> [doc _connect]
> Connect to the given server host/port. Throw an exception in case we couldn't sucessfully connect.
> [/doc _connect]
> [/field]
>
> [field][kwd]function[/kwd] host() : { port : [[/api/Int]], host : [[/api/sys/net/Host]] }
> [doc _host]
> Return the informations about our side of a connected socket.
> [/doc _host]
> [/field]
>
> [field][kwd]function[/kwd] listen( connections : [[/api/Int]] ) : [[/api/Void]]
> [doc _listen]
> Allow the socket to listen for incoming questions. The parameter tells how many pending connections we can have until they get refused. Use ''accept()'' to accept incoming connections.
> [/doc _listen]
> [/field]
>
> [field][kwd]function[/kwd] peer() : { port : [[/api/Int]], host : [[/api/sys/net/Host]] }
> [doc _peer]
> Return the informations about the other side of a connected socket.
> [/doc _peer]
> [/field]
>
> [field][kwd]function[/kwd] read() : [[/api/String]]
> [doc _read]
> Read the whole data available on the socket.
> [/doc _read]
> [/field]
>
> [field][kwd]function[/kwd] setBlocking( b : [[/api/Bool]] ) : [[/api/Void]]
> [doc _setBlocking]
> Change the blocking mode of the socket. A blocking socket is the default behavior. A non-blocking socket will abort blocking operations immediatly by throwing a haxe.io.Error.Blocking value.
> [/doc _setBlocking]
> [/field]
>
> [field][kwd]function[/kwd] setFastSend( b : [[/api/Bool]] ) : [[/api/Void]]
> [doc _setFastSend]
> Allows the socket to immediatly send the data when written to its output : this will cause less ping but might increase the number of packets / data size, especially when doing a lot of small writes.
> [/doc _setFastSend]
> [/field]
>
> [field][kwd]function[/kwd] setTimeout( timeout : [[/api/Float]] ) : [[/api/Void]]
> [doc _setTimeout]
> Gives a timeout after which blocking socket operations (such as reading and writing) will abort and throw an exception.
> [/doc _setTimeout]
> [/field]
>
> [field][kwd]function[/kwd] shutdown( read : [[/api/Bool]], write : [[/api/Bool]] ) : [[/api/Void]]
> [doc _shutdown]
> Shutdown the socket, either for reading or writing.
> [/doc _shutdown]
> [/field]
>
> [field][kwd]function[/kwd] waitForRead() : [[/api/Void]]
> [doc _waitForRead]
> Block until some data is available for read on the socket.
> [/doc _waitForRead]
> [/field]
>
> [field][kwd]function[/kwd] write( content : [[/api/String]] ) : [[/api/Void]]
> [doc _write]
> Write the whole data to the socket output.
> [/doc _write]
> [/field]
>
> [field][kwd]static[/kwd] [kwd]function[/kwd] select( read : [[/api/Array]]<[[/api/sys/net/Socket]]>, write : [[/api/Array]]<[[/api/sys/net/Socket]]>, others : [[/api/Array]]<[[/api/sys/net/Socket]]>, ?timeout : [[/api/Float]] ) : { write : [[/api/Array]]<[[/api/sys/net/Socket]]>, read : [[/api/Array]]<[[/api/sys/net/Socket]]>, others : [[/api/Array]]<[[/api/sys/net/Socket]]> }
> [doc s_select]
> Wait until one of the sockets groups is ready for the given operation : ''read'' contains sockets on which we want to wait for available data to be read, ''write'' contains sockets on which we want to wait until we are allowed to write some data to their output buffers, ''others'' contains sockets on which we want to wait for exceptional conditions. ''select'' will block until one of the condition is met, in which case it will return the sockets for which the condition was true. In case a ''timeout'' (in seconds) is specified, select might wait at worse until the timeout expires.
> [/doc s_select]
> [/field]
>
> [/api]
\ No newline at end of file
| Ver | Date | User | Action |
|---|---|---|---|
| #15006 | 2012-07-16 12:29:52 | api | View | Diff |
| #13539 | 2012-04-12 22:32:36 | api | View | Diff |
| #13538 | 2012-04-12 22:32:36 | api | Set title to Socket |
Previous | Next