net.Socket

Socket

package sys-net

extended by SslSocket, SslSocket, UdpSocket, Socket

Available on cpp, cs, hl, java, lua, macro, neko, php, python

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.

Constructor

new ()

Creates a new unconnected socket.

Variables

custom:Dynamic

Available on cpp, cs, hl, java, lua, macro, neko, php

A custom value that can be associated with the socket. Can be used to retreive your custom infos after a select.

custom:Dynamic

Available on python

A custom value that can be associated with the socket. Can be used to retreive your custom infos after a select.

read only input:Input

Available on cpp, cs, hl, java, lua, macro, neko, php

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.

read only input:Input

Available on python

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.

read only output:Output

Available on cpp, cs, hl, java, lua, macro, neko, php

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.

read only output:Output

Available on python

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.

Methods

accept ():Socket

Accept a new connected client. This will return a connected socket on which you can read/write some data.

bind (host:Host, port:Int):Void

Bind the socket to the given host/port so it can afterwards listen for connections there.

close ():Void

Closes the socket : make sure to properly close all your sockets or you will crash when you run out of file descriptors.

connect (host:Host, port:Int):Void

Connect to the given server host/port. Throw an exception in case we couldn't sucessfully connect.

host ():{port:Int, host:Host}

Return the informations about our side of a connected socket.

listen (connections:Int):Void

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.

peer ():{port:Int, host:Host}

Return the informations about the other side of a connected socket.

read ():String

Read the whole data available on the socket.

setBlocking (b:Bool):Void

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.

setFastSend (b:Bool):Void

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.

setTimeout (timeout:Float):Void

Gives a timeout after which blocking socket operations (such as reading and writing) will abort and throw an exception.

shutdown (read:Bool, write:Bool):Void

Shutdown the socket, either for reading or writing.

waitForRead ():Void

Block until some data is available for read on the socket.

write (content:String):Void

Write the whole data to the socket output.

Static methods

static select (read:Array<Socket>, write:Array<Socket>, others:Array<Socket>, ?timeout:Float):{write:Array<Socket>, read:Array<Socket>, others:Array<Socket>}

Available on cpp, hl, java, lua, macro, neko, php

Wait until one of the sockets groups is ready for the given operation : - readcontains 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.

static select (read:Array<Socket>, write:Array<Socket>, others:Array<Socket>, ?timeout:Float):{write:Array<Socket>, read:Array<Socket>, others:Array<Socket>}

Available on cs

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.

static select (read:Array<Socket>, write:Array<Socket>, others:Array<Socket>, ?timeout:Float):{write:Array<Socket>, read:Array<Socket>, others:Array<Socket>}

Available on python

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.

© 2005–2016 Haxe Foundation
Licensed under a MIT license.
http://api.haxe.org/sys/net/Socket.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部