PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/brl/monkeydoc/socket.monkeydoc

https://github.com/Sonickidnextgen/monkey_ambiguityfix_80a
Unknown | 341 lines | 153 code | 188 blank | 0 comment | 0 complexity | 5521bf5d632aeee5fdd96f7f3611d4ea MD5 | raw file
Possible License(s): GPL-3.0
  1. # Module brl.socket
  2. # Interface IOnConnectComplete
  3. # Method OnConnectComplete:Void( connected:Bool,source:Socket )
  4. This method is called when a asynchronous socket connect operation completes.
  5. @connected will be true if the connection was successful.
  6. Links: [[Socket.ConnectAsync]]
  7. # Interface IOnBindComplete
  8. # Method OnBindComplete:Void( bound:Bool,source:Socket )
  9. This method is called when a asynchronous socket bind operation completes.
  10. @bound will be true if the operation was successful.
  11. Links: [[Socket.BindAsync]]
  12. # Interface IOnAcceptComplete
  13. # Method OnAcceptComplete:Void( socket:Socket,source:Socket )
  14. This method is called when an asynchronous socket accept operation completes.
  15. @socket contains the incoming connection.
  16. If you want to accept another connection, you will need to call [[Socket.AcceptAsync]] again.
  17. Links: [[Socket.AcceptAsync]]
  18. # Interface IOnSendComplete
  19. # Method OnSendComplete:Void( data:DataBuffer,offset:Int,count:Int,source:Socket )
  20. This method is called when an asynchronous socket Send operation completes.
  21. @counts contains the number of bytes sent, and will either be the same as the number of bytes requested by SendAsync, or 0 if not all bytes could be sent.
  22. Links: [[Socket.SendAsync]]
  23. # Interface IOnSendToComplete
  24. # Method OnSendToComplete:Void( data:DataBuffer,offset:Int,count:Int,address:SocketAddress,source:Socket )
  25. This method is called when an asynchronous socket SendTo operation completes.
  26. @counts contains the number of bytes sent.
  27. Links: [[Socket.SendToAsync]]
  28. # Interface IOnReceiveComplete
  29. # Method OnReceiveComplete:Void( data:DataBuffer,offset:Int,count:Int,source:Socket )
  30. This method is called when an asynchronous socket Receive or ReceiveAll operation completes.
  31. @count contains the number of bytes received.
  32. Links: [[Socket.ReceiveAsync]], [[Socket.ReceiveAllAsync]]
  33. # Interface IOnReceiveFromComplete
  34. # Method OnReceiveFromComplete:Void( data:DataBuffer,offset:Int,count:Int,address:SocketAddress,source:Socket )
  35. This method is called when an asynchronous socket ReceiveFrom operation completes.
  36. @count contains the number of bytes received.
  37. Links: [[Socket.ReceiveFromAsync]]
  38. # Class SocketAddress
  39. # Method New()
  40. Creates a new empty socket adress.
  41. # Method New( host:String,port:int )
  42. Creates a new socket address with the given @host and @port.
  43. # Method New( address:SocketAddress )
  44. Creates a new socket address that is a copy of the given @address.
  45. # Method Host:String() Property
  46. Returns the socket address host.
  47. # Method Port:Int() Property
  48. Returns the socket address port.
  49. # Method ToString:String() Property
  50. Returns a string representation of the socket address.
  51. # Class Socket
  52. # Method New( protocol:String="stream" )
  53. Creates a new socket.
  54. The supported protocols are:
  55. | Protocol | Description
  56. | stream | TCP stream
  57. | server | TCP server
  58. | datagram | UDP datagram
  59. # Method Bind:Bool( host:String,port:Int )
  60. Binds the socket to a local host and port.
  61. If @host is "", the socket will be bound to a system allocated host address, generally "localhost" or "127.0.0.1".
  62. If @port is 0, the socket will be bound to a system allocated port number.
  63. Returns true if successful. This method will fail if the socket is already bound to a port, or the binding failed, for example if @port is already in use.
  64. In the case of server sockets, Bind will cause the server to start listening.
  65. Links: [[LocalAddress]]
  66. # Method BindAsync:Void( host:String,port:Int,onComplete:IOnBindComplete )
  67. Binds the socket to a local host and port asynchronously.
  68. The method returns immediately. Once the bind operation is complete, the [[OnBindComplete]] method of the @onComplete object is called.
  69. # Method Connect:Bool( host:String,port:Int )
  70. Connects the socket to a remote host.
  71. The method will block until the connection completes.
  72. Returns true if the connection was successful.
  73. The socket must be a stream or datagram socket.
  74. Links: [[RemoteAddress]]
  75. # Method ConnectAsync:Void( host:String,port:Int,onComplete:IOnConnectComplete )
  76. Connects a socket to a remote host asynchronously.
  77. The method returns immediately. Once the connection is complete, the [[OnConnectComplete]] method of the @onComplete object is called.
  78. The socket must be a stream or datagram socket.
  79. # Method Accept:Socket()
  80. Accepts a new connection from a remote host.
  81. The method will block until a new connection is accepted.
  82. The socket must be a server socket. If the socket has not been bound, it will first be bound to a system generated host address and port number.
  83. Links: [[Bind]]
  84. # Method AcceptAsync:Void( onComplete:IOnAcceptComplete )
  85. Accepts a new connection from a remote host asynchronously.
  86. The method returns immediately. Once a new connection is accepted, the [[OnAcceptComplete]] method of the @onComplete object is called.
  87. The socket must be a server socket.
  88. In order to allow multiple incoming connections, your code should call AcceptAsync again somewhere inside OnAcceptComplete.
  89. # Method Send:Int( data:DataBuffer,offset:Int,count:Int )
  90. Sends data to a remote host and returns the number of bytes sent.
  91. The method blocks until either all bytes of data have been sent or the socket is closed.
  92. The socket must be a connected stream or connected datagram socket.
  93. Links: [[Receive]]
  94. # Method SendAsync:Int( data:DataBuffer,offset:Int,count:Int,onComplete:IOnSendComplete )
  95. Sends data to a remote host asynchronously.
  96. The method returns immediately. Once all bytes of data have bben been sent or the socket is closed, the [[OnSendComplete]] method of the @onComplete object is called.
  97. The socket must be a connected stream or connected datagram socket.
  98. Note: Be careful not to modify @data while the operation is in progress.
  99. # Method SendTo:Int( data:DataBuffer,offset:Int,count:Int,address:SocketAddress )
  100. Sends data to the remote host specified by @address and returns the number of bytes sent.
  101. The method blocks until either all bytes have been sent or the socket is closed.
  102. The @address parameter must contain a valid socket address.
  103. The socket must be an unconnected datagram socket.
  104. Links: [[ReceiveFrom]]
  105. # Method SendToAsync:Int( data:DataBuffer,offset:Int,count:Int,address:SocketAddress,onComplete:IOnSendToComplete )
  106. Sends data to the remote host specified by @address asynchronously.
  107. The method returns immediately. Once all bytes of data have been sent or the socket is closed, the [[OnSendToComplete]] method of the @onComplete object is called.
  108. The @address parameter must contain a valid socket address.
  109. The socket must be an unconnected datagram socket.
  110. Note: Be careful not to modify @data or @address while the operation is in progress.
  111. # Method Receive:Int( data:DataBuffer,offset:Int,count:Int )
  112. Receives data from a remote host and returns the number of bytes received.
  113. The method blocks until either at least 1 byte of data has been received or the socket is closed.
  114. The socket must be a connected stream or connected datagram socket.
  115. Links: [[Send]]
  116. # Method ReceiveAsync:Int( data:DataBuffer,offset:Int,count:Int,onComplete:IOnReceiveComplete )
  117. Receives data from a remote host asynchronously.
  118. The method returns immediately. Once at least 1 byte of data has been received or the socket is closed, the [[OnReceiveComplete]] method of the @onComplete object is called.
  119. The socket must be a connected stream or connected datagram socket.
  120. Note: Be careful not to modify @data or @address while the operation is in progress.
  121. # Method ReceiveAll:Int( data:DataBuffer,offset:Int,count:Int )
  122. Receives data from a remote host and returns the number of bytes received.
  123. The method blocks until either @count bytes of data have been received or the socket is closed.
  124. The socket must be a connected stream or connected datagram socket.
  125. Links: [[Send]]
  126. # Method ReceiveAllAsync:Int( data:DataBuffer,offset:Int,count:Int,onComplete:IOnReceiveComplete )
  127. Receives data from a remote host asynchronously.
  128. The method returns immediately. Once either @count bytes of data have been received or the socket is closed, the [[OnReceiveComplete]] method of the @onComplete object is called.
  129. The socket must be a connected stream or connected datagram socket.
  130. Note: Be careful not to modify @data or @address while the operation is in progress.
  131. # Method ReceiveFrom:Int( data:DataBuffer,offset:Int,count:Int,address:SocketAddress )
  132. Receives data from a remote host and returns the number of bytes received.
  133. The method blocks until at least 1 byte of data is available or the socket is closed.
  134. The address of the remote host that the data was sent from is written to @address.
  135. The socket must be an unconnected datagram socket.
  136. # Method ReceiveFromAsync:Int( data:DataBuffer,offset:Int,count:Int,address:SocketAddress,onComplete:IOnReceiveFromComplete )
  137. Receives data from a remote host asynchronously.
  138. The method returns immediately. Once at least 1 byte of data has been received or the socket is closed, the [[OnReceiveFromComplete]] method of the @onComplete object is called.
  139. The address of the remote host that the data was sent from is written to @address.
  140. The socket must be an unconnected datagram socket.
  141. Note: Be careful not to modify @data or @address while the operation is in progress.
  142. # Method Protocol:String() Property
  143. Returns the socket protocol, either "stream", "server", or "datagram".
  144. # Method LocalAddress:SocketAddress() Property
  145. Returns the local address of the socket.
  146. # Method RemoteAddress:SocketAddress() Property
  147. Returns the remote address of the socket.
  148. # Method IsBound:Bool() Property
  149. Returns true if the socket is currently bound to a local address.
  150. Links: [[Bind]]
  151. # Method IsConnected:Bool() Property
  152. Return true id the socket is currently connected to a remote host.
  153. Links: [[Connect]]