PageRenderTime 16ms CodeModel.GetById 2ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/docs/reference/Networking/Socket/Socket/index.html

https://github.com/richcollins/io
HTML | 526 lines | 520 code | 6 blank | 0 comment | 0 complexity | 1a995a1788ddaa81a13f709afaeaf9b2 MD5 | raw file
  1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
  2		<html>
  3		<head>
  4		<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
  5		<title>Socket</title>
  6		<META HTTP-EQUIV="EXPIRES" CONTENT=0>
  7		<link rel="stylesheet" href="../../../../docs.css">
  8		</head>
  9		<body>
 10		
 11<br>
 12<h1>Io Reference</h1>
 13<br><br><br>
 14<br><br><br>
 15<a class='column' href='../../index.html'>Networking</a>
 16&nbsp;&nbsp;<font color=#ccc>/</font>&nbsp;&nbsp;
 17<a class='column' href='../index.html'>Socket</a>
 18&nbsp;&nbsp;<font color=#ccc>/</font>&nbsp;&nbsp;
 19<b>Socket</b>
 20<br><br><br>
 21<br><br><br>
 22<table border=0 cellspacing=0 style="margin-left:8em; width:40em; line-height:1.2em;">
 23<tr>
 24<td align=right></td>
 25<td></td>
 26<td>Interface to network communication.
 27Sockets will auto yield to other coroutines while waiting on a request.
 28All blocking operations use the timeout settings of the socket.
 29Reads are appended to the socket's read buffer which can 
 30be accessed using the readBuffer method.
 31
 32Example:
 33
 34<pre>	
 35socket := Socket clone setHost("www.yahoo.com") setPort(80) connect
 36if(socket error) then( write(socket error, "\n"); exit)
 37
 38socket write("GET /\n\n")
 39
 40while(socket read, Nop)
 41if(socket error) then(write(socket error, "\n"); exit)
 42
 43write("read ", socket readBuffer length, " bytes\n")
 44</pre>
 45</td></tr>
 46<tr><td colspan=3>&nbsp;</td></tr>
 47<tr><td colspan=3>&nbsp;</td></tr>
 48<tr><td colspan=3>&nbsp;</td></tr>
 49<tr>
 50<td align=right>
 51</td>
 52<td></td>
 53<td>
 54<hr align=left color=#ddd height=1>
 55<br><br>
 56<a name="Socket-acceptTimeout"></a><b>
 57acceptTimeout
 58</b>
 59<p>
 60<div class=slotDescription>
 61Returns the length of time in seconds for accept timeouts on the socket.
 62</div>
 63<a name="Socket-appendToWriteBuffer"></a><b>
 64appendToWriteBuffer(aSequence)
 65</b>
 66<p>
 67<div class=slotDescription>
 68Appends aSequence to the write buffer if it is non-nil. Returns self.
 69</div>
 70<a name="Socket-asyncAccept"></a><b>
 71asyncAccept(ipAddressObject)
 72</b>
 73<p>
 74<div class=slotDescription>
 75Immediately returns a socket for a connection if one is available or nil otherwise. Returns an Error object on error.
 76</div>
 77<a name="Socket-asyncBind"></a><b>
 78asyncBind
 79</b>
 80<p>
 81<div class=slotDescription>
 82Binds the socket and returns self immediately or an Error object on error.
 83</div>
 84<a name="Socket-asyncConnect"></a><b>
 85asyncConnect(ipAddressObject)
 86</b>
 87<p>
 88<div class=slotDescription>
 89Connects to the given IPAddress and returns self or an Error object on error.
 90</div>
 91<a name="Socket-asyncListen"></a><b>
 92asyncListen
 93</b>
 94<p>
 95<div class=slotDescription>
 96Listens to the socket and returns self immediately or an Error object on error.
 97</div>
 98<a name="Socket-asyncStreamOpen"></a><b>
 99asyncStreamOpen
100</b>
101<p>
102<div class=slotDescription>
103Submits an async request to open the socket in stream mode and returns self immediately or an Error object on error.
104</div>
105<a name="Socket-asyncStreamRead"></a><b>
106asyncStreamRead(aSeq, readSize)
107</b>
108<p>
109<div class=slotDescription>
110Reads up to readSize number of bytes into aSeq if data is available. 
111	Returns self immediately if successful. Returns an error object on Error. Returns nil if the socket is disconnected.
112</div>
113<a name="Socket-asyncStreamWrite"></a><b>
114asyncStreamWrite(aSeq, start, writeSize)
115</b>
116<p>
117<div class=slotDescription>
118Writes the slice of aSeq from start to start + writeSize to the socket.
119	Returns self immediately if successful, otherwise closes the socket. 
120	Returns an error object on Error. 
121	Returns nil if the socket is disconnected.
122</div>
123<a name="Socket-asyncUdpOpen"></a><b>
124asyncUdpOpen
125</b>
126<p>
127<div class=slotDescription>
128Submits an async request to open the socket in UDP mode and returns self immediately or an Error object on error.
129</div>
130<a name="Socket-asyncUdpRead"></a><b>
131asyncUdpRead(ipAddress, aSeq, readSize)
132</b>
133<p>
134<div class=slotDescription>
135Reads up to readSize number of bytes from ipAddress into aSeq if data is available. 
136	Returns self immediately if successful. Returns an error object on Error. Returns nil if the socket is disconnected.
137</div>
138<a name="Socket-asyncUdpWrite"></a><b>
139asyncUdpWrite(ipAddress, aSeq, startIndex, readSize)
140</b>
141<p>
142<div class=slotDescription>
143Writes readsize bytes from aSeq starting at startIndex to ipAddress. 
144	Returns self immediately if successful. Returns an error object on Error. Returns nil if the socket is disconnected.
145</div>
146<a name="Socket-bytesPerRead"></a><b>
147bytesPerRead
148</b>
149<p>
150<div class=slotDescription>
151Returns number of bytes to read per read call.
152</div>
153<a name="Socket-bytesPerWrite"></a><b>
154bytesPerWrite
155</b>
156<p>
157<div class=slotDescription>
158Returns number of bytes to write per write call.
159</div>
160<a name="Socket-close"></a><b>
161close
162</b>
163<p>
164<div class=slotDescription>
165Closes the socket and returns self. Returns nil on error.
166</div>
167<a name="Socket-connect"></a><b>
168connect
169</b>
170<p>
171<div class=slotDescription>
172Connects to the socket's host. Returns self on success or an Error object on error.
173</div>
174<a name="Socket-connectTimeout"></a><b>
175connectTimeout
176</b>
177<p>
178<div class=slotDescription>
179Returns the length of time in seconds for connect timeouts on the socket.
180</div>
181<a name="Socket-descriptorId"></a><b>
182descriptorId
183</b>
184<p>
185<div class=slotDescription>
186Returns the socket's file descriptor id as a Number.
187</div>
188<a name="Socket-errorDescription"></a><b>
189errorDescription
190</b>
191<p>
192<div class=slotDescription>
193Returns a description of the last error on the socket as a string.
194</div>
195<a name="Socket-errorNumber"></a><b>
196errorNumber
197</b>
198<p>
199<div class=slotDescription>
200Returns the socket error number for the last error.
201</div>
202<a name="Socket-getSocketReadLowWaterMark"></a><b>
203getSocketReadLowWaterMark
204</b>
205<p>
206<div class=slotDescription>
207Returns the read low water mark for the socket on success or nil on error.
208</div>
209<a name="Socket-getSocketWriteLowWaterMark"></a><b>
210getSocketWriteLowWaterMark
211</b>
212<p>
213<div class=slotDescription>
214Returns the write low water mark for the socket on success or nil on error.
215</div>
216<a name="Socket-host"></a><b>
217host
218</b>
219<p>
220<div class=slotDescription>
221Returns the host for the socket.
222</div>
223<a name="Socket-ipAddress"></a><b>
224ipAddress
225</b>
226<p>
227<div class=slotDescription>
228Returns the IpAddress object for the socket.
229</div>
230<a name="Socket-isOpen"></a><b>
231isOpen
232</b>
233<p>
234<div class=slotDescription>
235Returns true if the socket is open, false otherwise.
236</div>
237<a name="Socket-isStream"></a><b>
238isStream
239</b>
240<p>
241<div class=slotDescription>
242Returns true if the socket is a stream, false otherwise.
243</div>
244<a name="Socket-isValid"></a><b>
245isValid
246</b>
247<p>
248<div class=slotDescription>
249Returns true if the socket is in valid state, closes the socket and returns false otherwise.
250</div>
251<a name="Socket-port"></a><b>
252port
253</b>
254<p>
255<div class=slotDescription>
256Returns the port number for the socket.
257</div>
258<a name="Socket-readBytes"></a><b>
259readBytes(numBytes)
260</b>
261<p>
262<div class=slotDescription>
263Reads the socket until its readBuffer is numBytes long, then returns a Sequence
264	containing the first numBytes of readBuffer's contents and clips that section from the readBuffer.
265</div>
266<a name="Socket-readListMessage"></a><b>
267readListMessage
268</b>
269<p>
270<div class=slotDescription>
271A shortcut for List fromEncodedList(socket readMessage).
272</div>
273<a name="Socket-readMessage"></a><b>
274readMessage
275</b>
276<p>
277<div class=slotDescription>
278Empties the readBuffer and reads a 4 byte uint32 in network byte order. 
279	This number is the number of bytes in the message payload which are 
280	then read into the socket's readBuffer. The readBuffer is returned.
281</div>
282<a name="Socket-readTimeout"></a><b>
283readTimeout
284</b>
285<p>
286<div class=slotDescription>
287Returns the length of time in seconds for read timeouts on the socket.
288</div>
289<a name="Socket-readUntilSeq"></a><b>
290readUntilSeq(aSequence)
291</b>
292<p>
293<div class=slotDescription>
294Reads the socket until its readBuffer contains aSequence, then returns a Sequence
295	containing the readBuffer's contents up to (but not including) aSequence and clips that section from the readBuffer.
296</div>
297<a name="Socket-serverOpen"></a><b>
298serverOpen
299</b>
300<p>
301<div class=slotDescription>
302Opens the socket as a stream, binds it to its ipAddress and calls asyncListen to prepare the socket to accept connections.
303	Returns self on success or an Error object on error.
304</div>
305<a name="Socket-serverWaitForConnection"></a><b>
306serverWaitForConnection
307</b>
308<p>
309<div class=slotDescription>
310Waits for a connection or timeout. When a connection is received, this method returns the connection socket. 
311	An Error object is returned on timeour or error.
312</div>
313<a name="Socket-setAcceptTimeout"></a><b>
314setAcceptTimeout(seconds)
315</b>
316<p>
317<div class=slotDescription>
318Sets the length of time in seconds for accept timeouts on the socket. Returns self.
319</div>
320<a name="Socket-setBytesPerRead"></a><b>
321setBytesPerRead(numberOfBytes)
322</b>
323<p>
324<div class=slotDescription>
325Sets number of bytes to read per read call. Returns self.
326</div>
327<a name="Socket-setBytesPerWrite"></a><b>
328setBytesPerWrite(numberOfBytes)
329</b>
330<p>
331<div class=slotDescription>
332Sets number of bytes to write per write call. Returns self.
333</div>
334<a name="Socket-setConnectTimeout"></a><b>
335setConnectTimeout(seconds)
336</b>
337<p>
338<div class=slotDescription>
339Sets the length of time in seconds for connect timeouts on the socket. Returns self.
340</div>
341<a name="Socket-setHost"></a><b>
342setHost(hostName)
343</b>
344<p>
345<div class=slotDescription>
346Translates hostName to an IP using asynchronous DNS and sets 
347the host attribute. Returns self.
348</div>
349<a name="Socket-setHost"></a><b>
350setHost(hostNameOrIpString)
351</b>
352<p>
353<div class=slotDescription>
354Set the host for the socket. Returns self on success, an Error object otherwise.
355</div>
356<a name="Socket-setIpAddress"></a><b>
357setIpAddress(ipAddressObject)
358</b>
359<p>
360<div class=slotDescription>
361Sets the ipAddress for the socket. Returns self. The setHost() method should generally be used to set the host instead of this method.
362</div>
363<a name="Socket-setNoDelay"></a><b>
364setNoDelay
365</b>
366<p>
367<div class=slotDescription>
368Sets the socket to be no-delay. Returns self on success or nil on error.
369</div>
370<a name="Socket-setPort"></a><b>
371setPort(portNumber)
372</b>
373<p>
374<div class=slotDescription>
375Sets the port number for the socket, returns self.
376</div>
377<a name="Socket-setReadTimeout"></a><b>
378setReadTimeout(seconds)
379</b>
380<p>
381<div class=slotDescription>
382Sets the length of time in seconds for read timeouts on the socket. Returns self.
383</div>
384<a name="Socket-setSocketReadBufferSize"></a><b>
385setSocketReadBufferSize(numberOfBytes)
386</b>
387<p>
388<div class=slotDescription>
389Sets the read buffer size for the socket. Returns self on success or nil on error.
390</div>
391<a name="Socket-setSocketReadLowWaterMark"></a><b>
392setSocketReadLowWaterMark(numberOfBytes)
393</b>
394<p>
395<div class=slotDescription>
396Sets the read low water mark for the socket. Returns self on success or nil on error.
397</div>
398<a name="Socket-setSocketWriteBufferSize"></a><b>
399setSocketWriteBufferSize(numberOfBytes)
400</b>
401<p>
402<div class=slotDescription>
403Sets the write buffer size for the socket. Returns self on success or nil on error.
404</div>
405<a name="Socket-setSocketWriteLowWaterMark"></a><b>
406setSocketWriteLowWaterMark(numberOfBytes)
407</b>
408<p>
409<div class=slotDescription>
410Sets the write low water mark for the socket. Returns self on success or nil on error.
411</div>
412<a name="Socket-setWriteTimeout"></a><b>
413setWriteTimeout(seconds)
414</b>
415<p>
416<div class=slotDescription>
417Sets the length of time in seconds for write timeouts on the socket. Returns self.
418</div>
419<a name="Socket-streamOpen"></a><b>
420streamOpen
421</b>
422<p>
423<div class=slotDescription>
424Opens the socket in stream mode. Returns self.
425</div>
426<a name="Socket-streamRead"></a><b>
427streamRead(numberOfBytes)
428</b>
429<p>
430<div class=slotDescription>
431Reads numberOfBytes from the socket into the socket's readBuffer. 
432	Returns self when all bytes are read or an Error object on error.
433</div>
434<a name="Socket-streamReadNextChunk"></a><b>
435streamReadNextChunk(optionalProgressBlock)
436</b>
437<p>
438<div class=slotDescription>
439Waits for incoming data on the socket and when found, reads any available data and returns self. 
440	Returns self on success or an Error object on error or timeout.
441</div>
442<a name="Socket-streamReadWhileOpen"></a><b>
443streamReadWhileOpen
444</b>
445<p>
446<div class=slotDescription>
447Reads the stream into the socket's readBuffer until it closes.
448	Returns self on success or an Error object on error.
449</div>
450<a name="Socket-streamWrite"></a><b>
451streamWrite(buffer, optionalProgressBlock)
452</b>
453<p>
454<div class=slotDescription>
455Writes buffer to the socket. 
456	If optionalProgressBlock is supplied, it is periodically called with the number of bytes written as an argument.
457	Returns self on success or an Error object on error.
458</div>
459<a name="Socket-udpOpen"></a><b>
460udpOpen
461</b>
462<p>
463<div class=slotDescription>
464Opens the socket in UDP (connectionless) mode. Returns self.
465</div>
466<a name="Socket-udpRead"></a><b>
467udpRead(ipAddress, numBytes)
468</b>
469<p>
470<div class=slotDescription>
471Waits for and reads numBytes of udp data from the specified ipAddress into the socket's readBuffer.
472	Returns self on success or an Error object on error.
473</div>
474<a name="Socket-udpReadNextChunk"></a><b>
475udpReadNextChunk(ipAddress)
476</b>
477<p>
478<div class=slotDescription>
479Waits to receive UDP data from the specified ipAddress. 
480	As soon as any data is available, it reads all of it into the socket's readBuffer.
481	Returns self on success or an Error object on error.
482</div>
483<a name="Socket-udpWrite"></a><b>
484udpWrite
485</b>
486<p>
487<div class=slotDescription>
488Same as asyncUdpWrite.
489</div>
490<a name="Socket-writeFromBuffer"></a><b>
491writeFromBuffer(optionalProgressBlock)
492</b>
493<p>
494<div class=slotDescription>
495Writes the contents of the socket's writeBuffer to the socket. 
496	If optionalProgressBlock is supplied, it is periodically called with the number of bytes written as an argument.
497	Returns self on success or an Error object on error.
498</div>
499<a name="Socket-writeListMessage"></a><b>
500writeListMessage(aList)
501</b>
502<p>
503<div class=slotDescription>
504A shortcut for writeMessage(aList asEncodedList).
505</div>
506<a name="Socket-writeMessage"></a><b>
507writeMessage(aSeq)
508</b>
509<p>
510<div class=slotDescription>
511Writes a 4 byte uint32 in network byte order containing the size of aSeq. 
512	Then writes the bytes in aSeq and returns self.
513</div>
514<a name="Socket-writeTimeout"></a><b>
515writeTimeout
516</b>
517<p>
518<div class=slotDescription>
519Returns the length of time in seconds for write timeouts on the socket.
520</div>
521</td>
522</tr>
523</table>
524<br><br><br><br><br>
525</body>
526</html>