PageRenderTime 30ms CodeModel.GetById 21ms app.highlight 6ms RepoModel.GetById 1ms 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
  1
  2# Module brl.socket
  3
  4
  5# Interface IOnConnectComplete
  6
  7# Method OnConnectComplete:Void( connected:Bool,source:Socket )
  8
  9This method is called when a asynchronous socket connect operation completes.
 10
 11@connected will be true if the connection was successful.
 12
 13Links: [[Socket.ConnectAsync]]
 14
 15
 16# Interface IOnBindComplete
 17
 18# Method OnBindComplete:Void( bound:Bool,source:Socket )
 19
 20This method is called when a asynchronous socket bind operation completes.
 21
 22@bound will be true if the operation was successful.
 23
 24Links: [[Socket.BindAsync]]
 25
 26
 27# Interface IOnAcceptComplete
 28
 29# Method OnAcceptComplete:Void( socket:Socket,source:Socket )
 30
 31This method is called when an asynchronous socket accept operation completes.
 32
 33@socket contains the incoming connection.
 34
 35If you want to accept another connection, you will need to call [[Socket.AcceptAsync]] again.
 36
 37Links: [[Socket.AcceptAsync]]
 38
 39
 40# Interface IOnSendComplete
 41
 42# Method OnSendComplete:Void( data:DataBuffer,offset:Int,count:Int,source:Socket )
 43
 44This method is called when an asynchronous socket Send operation completes.
 45
 46@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.
 47
 48Links: [[Socket.SendAsync]]
 49
 50
 51# Interface IOnSendToComplete
 52
 53# Method OnSendToComplete:Void( data:DataBuffer,offset:Int,count:Int,address:SocketAddress,source:Socket )
 54
 55This method is called when an asynchronous socket SendTo operation completes.
 56
 57@counts contains the number of bytes sent.
 58
 59Links: [[Socket.SendToAsync]]
 60
 61
 62
 63# Interface IOnReceiveComplete
 64
 65# Method OnReceiveComplete:Void( data:DataBuffer,offset:Int,count:Int,source:Socket )
 66
 67This method is called when an asynchronous socket Receive or ReceiveAll operation completes.
 68
 69@count contains the number of bytes received.
 70
 71Links: [[Socket.ReceiveAsync]], [[Socket.ReceiveAllAsync]]
 72
 73
 74# Interface IOnReceiveFromComplete
 75
 76# Method OnReceiveFromComplete:Void( data:DataBuffer,offset:Int,count:Int,address:SocketAddress,source:Socket )
 77
 78This method is called when an asynchronous socket ReceiveFrom operation completes.
 79
 80@count contains the number of bytes received.
 81
 82Links: [[Socket.ReceiveFromAsync]]
 83
 84
 85# Class SocketAddress
 86
 87# Method New()
 88
 89Creates a new empty socket adress.
 90
 91
 92# Method New( host:String,port:int )
 93
 94Creates a new socket address with the given @host and @port.
 95
 96
 97# Method New( address:SocketAddress )
 98
 99Creates a new socket address that is a copy of the given @address.
100
101
102# Method Host:String() Property
103
104Returns the socket address host.
105
106
107# Method Port:Int() Property
108
109Returns the socket address port.
110
111
112# Method ToString:String() Property
113
114Returns a string representation of the socket address.
115
116
117# Class Socket
118
119# Method New( protocol:String="stream" )
120
121Creates a new socket.
122
123The supported protocols are:
124
125| Protocol	| Description
126| stream	| TCP stream
127| server	| TCP server
128| datagram	| UDP datagram 
129
130
131# Method Bind:Bool( host:String,port:Int )
132
133Binds the socket to a local host and port.
134
135If @host is "", the socket will be bound to a system allocated host address, generally "localhost" or "127.0.0.1".
136
137If @port is 0, the socket will be bound to a system allocated port number.
138
139Returns 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.
140
141In the case of server sockets, Bind will cause the server to start listening.
142
143Links: [[LocalAddress]]
144
145
146# Method BindAsync:Void( host:String,port:Int,onComplete:IOnBindComplete )
147
148Binds the socket to a local host and port asynchronously.
149
150The method returns immediately. Once the bind operation is complete, the [[OnBindComplete]] method of the @onComplete object is called.
151
152
153# Method Connect:Bool( host:String,port:Int )
154
155Connects the socket to a remote host.
156
157The method will block until the connection completes.
158
159Returns true if the connection was successful.
160
161The socket must be a stream or datagram socket.
162
163Links: [[RemoteAddress]]
164
165
166# Method ConnectAsync:Void( host:String,port:Int,onComplete:IOnConnectComplete )
167
168Connects a socket to a remote host asynchronously.
169
170The method returns immediately. Once the connection is complete, the [[OnConnectComplete]] method of the @onComplete object is called.
171
172The socket must be a stream or datagram socket.
173
174
175# Method Accept:Socket()
176
177Accepts a new connection from a remote host.
178
179The method will block until a new connection is accepted.
180
181The 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.
182
183Links: [[Bind]]
184
185
186# Method AcceptAsync:Void( onComplete:IOnAcceptComplete )
187
188Accepts a new connection from a remote host asynchronously.
189
190The method returns immediately. Once a new connection is accepted, the [[OnAcceptComplete]] method of the @onComplete object is called.
191
192The socket must be a server socket.
193
194In order to allow multiple incoming connections, your code should call AcceptAsync again somewhere inside OnAcceptComplete.
195
196
197# Method Send:Int( data:DataBuffer,offset:Int,count:Int )
198
199Sends data to a remote host and returns the number of bytes sent.
200
201The method blocks until either all bytes of data have been sent or the socket is closed.
202
203The socket must be a connected stream or connected datagram socket.
204
205Links: [[Receive]]
206
207
208# Method SendAsync:Int( data:DataBuffer,offset:Int,count:Int,onComplete:IOnSendComplete )
209
210Sends data to a remote host asynchronously.
211
212The 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.
213
214The socket must be a connected stream or connected datagram socket.
215
216
217
218Note: Be careful not to modify @data while the operation is in progress.
219
220
221# Method SendTo:Int( data:DataBuffer,offset:Int,count:Int,address:SocketAddress )
222
223Sends data to the remote host specified by @address and returns the number of bytes sent.
224
225The method blocks until either all bytes have been sent or the socket is closed.
226
227The @address parameter must contain a valid socket address.
228
229The socket must be an unconnected datagram socket.
230
231Links: [[ReceiveFrom]]
232
233
234# Method SendToAsync:Int( data:DataBuffer,offset:Int,count:Int,address:SocketAddress,onComplete:IOnSendToComplete )
235
236Sends data to the remote host specified by @address asynchronously.
237
238The 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.
239
240The @address parameter must contain a valid socket address.
241
242The socket must be an unconnected datagram socket.
243
244Note: Be careful not to modify @data or @address while the operation is in progress.
245
246
247# Method Receive:Int( data:DataBuffer,offset:Int,count:Int )
248
249Receives data from a remote host and returns the number of bytes received.
250
251The method blocks until either at least 1 byte of data has been received or the socket is closed.
252
253The socket must be a connected stream or connected datagram socket.
254
255Links: [[Send]]
256
257
258# Method ReceiveAsync:Int( data:DataBuffer,offset:Int,count:Int,onComplete:IOnReceiveComplete )
259
260Receives data from a remote host asynchronously.
261
262The 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.
263
264The socket must be a connected stream or connected datagram socket.
265
266Note: Be careful not to modify @data or @address while the operation is in progress.
267
268
269# Method ReceiveAll:Int( data:DataBuffer,offset:Int,count:Int )
270
271Receives data from a remote host and returns the number of bytes received.
272
273The method blocks until either @count bytes of data have been received or the socket is closed.
274
275The socket must be a connected stream or connected datagram socket.
276
277Links: [[Send]]
278
279
280# Method ReceiveAllAsync:Int( data:DataBuffer,offset:Int,count:Int,onComplete:IOnReceiveComplete )
281
282Receives data from a remote host asynchronously.
283
284The 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.
285
286The socket must be a connected stream or connected datagram socket.
287
288Note: Be careful not to modify @data or @address while the operation is in progress.
289
290
291# Method ReceiveFrom:Int( data:DataBuffer,offset:Int,count:Int,address:SocketAddress )
292
293Receives data from a remote host and returns the number of bytes received.
294
295The method blocks until at least 1 byte of data is available or the socket is closed.
296
297The address of the remote host that the data was sent from is written to @address.
298
299The socket must be an unconnected datagram socket.
300
301
302# Method ReceiveFromAsync:Int( data:DataBuffer,offset:Int,count:Int,address:SocketAddress,onComplete:IOnReceiveFromComplete )
303
304Receives data from a remote host asynchronously.
305
306The 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.
307
308The address of the remote host that the data was sent from is written to @address.
309
310The socket must be an unconnected datagram socket.
311
312Note: Be careful not to modify @data or @address while the operation is in progress.
313
314
315# Method Protocol:String() Property
316
317Returns the socket protocol, either "stream", "server", or "datagram".
318
319
320# Method LocalAddress:SocketAddress() Property
321
322Returns the local address of the socket.
323
324
325# Method RemoteAddress:SocketAddress() Property
326
327Returns the remote address of the socket.
328
329
330# Method IsBound:Bool() Property
331
332Returns true if the socket is currently bound to a local address.
333
334Links: [[Bind]]
335
336
337# Method IsConnected:Bool() Property
338
339Return true id the socket is currently connected to a remote host.
340
341Links: [[Connect]]