HomeForumSourceResearchGuide
Sign in to contribute to source. how it works
Type definition file net.TCPSocket by barry
expand copy to clipboardexpand
uses TCPServerSocket

data NetworkEndpoint{
	char address[]
	int port
	}

/*
{"description" : "Communicate over the TCP network protocol. New connections can be established either using 'connect' (for a client) or by using 'accept' (for a server, in conjunction with a TCPServerSocket instance)."}
*/

interface TCPSocket extends net.Stream {

	/* {"@description" : "In non-blocking mode, this event is fired when a send() fails due to the socket not being ready. The socket should be set for write-ability notification in e.g. a TCPMonitor, then when a writeable notification arrives, sendBuffer() should be called to send pending bytes."} */
	event sendWait(Data d)

	/* {"@description" : "Connect to the given TCP server."} */
	bool connect(char address[], int port)
	
	/* {"@description" : "Establish a TCP connection by accepting a new client via a TCP server socket."} */
	bool accept(TCPServerSocket server)
	
	/* {"@description" : "Disconnect (terminate) this TCP connection."} */
	void disconnect()
	
	/* {"@description" : "Get the endpoint details of the remote end of this TCP connection."} */
	NetworkEndpoint getRemoteEndpoint()
	
	/* {"@description" : "Get the endpoint details of the local end of this TCP connection."} */
	NetworkEndpoint getLocalEndpoint()

	/* {"@description" : "Switch the socket to non-blocking mode. In this mode, calls to recv() will always return 'immediately' but may read no data. Non-blocking TCP sockets are normally used with net.TCPMonitor. The optional data instance is delivered via any sendWait() events."} */
	bool setNonBlocking(opt store Data sendWaitData)

	/* {"@description" : "In non-blocking mode only, send any pending bytes; this should be called after a write-ability notification has been received from a TCPMonitor."} */
	int sendBuffer()

	/* {"@description" : "In non-blocking mode only, check how many bytes are in the send buffer pending write-ability."} */
	int getBufferUnsent()

	/* {"@description" : "Test whether or not this socket is connected (this is useful only in non-blocking mode, to determine whether a null return from recv() is temporary or terminal)."} */
	bool connected()
	}
Revision history
To propose a new revision to this entity, use dana source put -ut your/new/version.dn -n net.TCPSocket -m "reason for update" -u yourUsername
Version 2 by barry
Version 1 (this version) by barry
Notes for this version: Standard Library Initialisation