JWebSocketFactory 工厂类根据 jwebsocket.xml配置文件初始化 Jwebsocket引擎,服务器以及plugin chain.
JWebSocketFactory: Starting jWebSocket Server sub system
....
JWebSocketLoader: Loading jWebSocket.xml
AbstractJWebSocketInitializer: Instantiating engine...
2011-01-05 18:19:41,235 INFO - AbstractJWebSocketInitializer: Engine tcp0 instantiated.
2011-01-05 18:19:41,236 DEBUG - JWebSocketFactory: Initializing servers...
2011-01-05 18:19:41,287 INFO - AbstractJWebSocketInitializer: Custom servers instantiated.
2011-01-05 18:19:41,287 DEBUG - AbstractJWebSocketInitializer: server=[org.jwebsocket.server.CcicJwsServer@19b719d
...........
加载一系列plugins.....
这里有一FlashBridgePlugIn值得注意,是用来做浏览器兼容用的,因为wesocket 是html5的一部分,很多浏览器不支持,所以用
flash来做桥,websocket协议的核心无非是在浏览器端实现socket接口,flash本身提供socket编程接口,所以这里用flash做桥。。
端口为843。
2011-01-05 18:19:41,393 DEBUG - JWebSocketFactory: Initializing filters...
2011-01-05 18:19:41,393 DEBUG - TokenFilterChain: Adding token filter cjf0...
2011-01-05 18:19:41,394 INFO - JWebSocketFactory: Filters initialized.
2011-01-05 18:19:41,394 DEBUG - JWebSocketFactory: Starting engine 'tcp0'...
2011-01-05 18:19:41,395 DEBUG - TCPEngine: Starting TCP engine 'tcp0' at port 8787...
2011-01-05 18:19:41,401 INFO - TCPEngine: TCP engine 'tcp0' started' at port 8787.
2011-01-05 18:19:41,402 DEBUG - JWebSocketFactory: Starting servers...
2011-01-05 18:19:41,402 INFO - JWebSocketFactory: jWebSocket server startup complete
。。。。。。。。。
当浏览器 客户端连接时,握手过程。。。
TCPEngine: Received Header (GET / HTTP/1.1/nUpgrade: WebSocket/nConnection: Upgrade/nHost: 10.10.10.182:8787/nOrigin: http://10.10.10.122/nCookie: _login_username_cookie=233223432; _login_user_cookie_id=1292484678732_232323-295817044/n)
TCPEngine 接口客户端请求,
TCPEngine: Parsed header (host: 10.10.10.182:8787, origin: http://10.10.10.122, location: ws://10.10.10.122:8787/, path: /, searchString: )
解析请求头,,,
TCPEngine: Sent handshake (HTTP/1.1 101 Web Socket Protocol Handshake/nUpgrade: WebSocket/nConnection: Upgrade/nWebSocket-Origin: http://10.10.10.122/nWebSocket-Location: ws://10.10.10.122:8787//n/n)
响应,握手。。
TCPEngine$EngineListener: Starting connector... 启动connector 实例,
TCPConnector: Starting TCP connector...
2011-01-05 18:18:49,381 INFO - TCPConnector: Started TCP connector on port 4452.
2011-01-05 18:18:49,382 DEBUG - TCPEngine: Detected new connector at port 4452.
2011-01-05 18:18:49,382 DEBUG - tccJwsServer: Processing connector '4452' started...
2011-01-05 18:18:49,382 DEBUG - BasePlugInChain: Notifying plug-ins that connector started...
2011-01-05 18:18:49,385 DEBUG - PlugIn: Sending welcome...
2011-01-05 18:18:49,385 DEBUG - Server: Sending token '{sid=9d7bf2c4f98ba4aa1552064af22e0853,type=welcome,timeout=120000}' to '10.10.10.158:4452'...
2011-01-05 18:18:49,923 DEBUG - 、Server: Processing token '{number400=34234324,pwd=,utid=164,cno=2000,type=login} from '10.10.10.158:4452'...
jwebsocket 服务器支持单线程+异步IO及多线程两种模式,对于多线程模式,这里TCPEngine为一个线程,负责握手,一旦握手成功则启动TCPConnector线程处理客户端与服务器之间的数据传输。