Project

General

Profile

Statistics
| Branch: | Revision:

colonymech / docs / www / colonyscout / internal / includes / uploadify / com / adobe / protocols / dict / util / SocketHelper.as @ f59acf11

History | View | Annotate | Download (1.34 KB)

1
package com.adobe.protocols.dict.util
2
{
3
	import com.adobe.net.proxies.RFC2817Socket;
4
	import flash.events.ProgressEvent;
5

    
6
	public class SocketHelper
7
		extends RFC2817Socket
8
	{
9
		private var terminator:String = "\r\n.\r\n";
10
		private var buffer:String;
11
		public static var COMPLETE_RESPONSE:String = "completeResponse";
12

    
13
		public function SocketHelper()
14
		{
15
			super();
16
			buffer = new String();
17
			addEventListener(ProgressEvent.SOCKET_DATA, incomingData);
18
		}
19

    
20
		private function incomingData(event:ProgressEvent):void
21
		{
22
			buffer += readUTFBytes(bytesAvailable);
23
			buffer = buffer.replace(/250[^\r\n]+\r\n/, ""); // Get rid of all 250s. Don't need them.
24
			var codeStr:String = buffer.substring(0, 3);
25
			if (!isNaN(parseInt(codeStr)))
26
			{
27
				var code:uint = uint(codeStr);
28
				if (code == 150 || code >= 200)
29
				{
30
					buffer = buffer.replace("\r\n", this.terminator);
31
				}
32
			}
33

    
34
			while (buffer.indexOf(this.terminator) != -1)
35
			{
36
				var chunk:String = buffer.substring(0, buffer.indexOf(this.terminator));
37
				buffer = buffer.substring(chunk.length + this.terminator.length, buffer.length);
38
				throwResponseEvent(chunk);
39
			}
40
		}
41
		
42
		private function throwResponseEvent(response:String):void
43
		{
44
			var responseEvent:CompleteResponseEvent = new CompleteResponseEvent();
45
			responseEvent.response = response;
46
			dispatchEvent(responseEvent);			
47
		}
48
	}
49
}