//Call back when the socket to the server has connected
        public static void connectCallBack(IAsyncResult ar)
        {
            ProxyConnection conn = (ProxyConnection)ar.AsyncState;

            try
            {
                conn.serverSocket.EndConnect(ar);

                logger.info("[{0}] ProxyConnection#{1}--connected to Server.   Server: {2}, Local: {3}.",
                            conn.serviceName,
                            conn.connNumber,
                            conn.serverSocket.RemoteEndPoint,
                            conn.serverSocket.LocalEndPoint);

                //create task for proxying data between the client and server socket
                ProxySwapDataTask dataTask = new ProxySwapDataTask(conn);
                ThreadPool.getInstance().addTask(dataTask);
            }
            catch (SocketException se)
            {
                if (!conn.isShutdown)
                {
                    if (se.ErrorCode == 10060)
                    {
                        logger.error("[{0}] Conn#{1} Socket Connect Timed out for server {2}",
                                     conn.serviceName, conn.connNumber, conn.serverEP);
                    }
                    else
                    {
                        logger.error("[{0}] Conn#{1} Socket Error occurred when connecting to server. Error Code is: {2}",
                                     conn.serviceName, conn.connNumber, se.ErrorCode);
                    }

                    conn.Release();
                }
            }
            catch (Exception e)
            {
                if (!conn.isShutdown)
                {
                    logger.error("[{0}] Conn# {1} Error occurred when connecting to server. Error is: {2}",
                                 conn.serviceName, conn.connNumber, e);
                    conn.Release();
                }
            }
            finally
            {
                conn = null;                  //free reference to the object
            }
        }
Esempio n. 2
0
		//Call back when the socket to the server has connected
		public static void connectCallBack(IAsyncResult ar)
		{
			ProxyConnection conn = (ProxyConnection) ar.AsyncState;

			try
			{
				conn.serverSocket.EndConnect(ar); 
							
				logger.info("[{0}] ProxyConnection#{1}--connected to Server.   Server: {2}, Local: {3}.",
					conn.serviceName,
					conn.connNumber,
					conn.serverSocket.RemoteEndPoint, 
					conn.serverSocket.LocalEndPoint);

				//create task for proxying data between the client and server socket
				ProxySwapDataTask dataTask  = new ProxySwapDataTask(conn);
				ThreadPool.getInstance().addTask(dataTask);
			} 
			catch (SocketException se)
			{
				if (!conn.isShutdown)
				{
					if (se.ErrorCode == 10060)
					{
						logger.error("[{0}] Conn#{1} Socket Connect Timed out for server {2}",
							conn.serviceName, conn.connNumber, conn.serverEP);
					}
					else
					{
						logger.error("[{0}] Conn#{1} Socket Error occurred when connecting to server. Error Code is: {2}",
							conn.serviceName, conn.connNumber, se.ErrorCode);
					}
					
					conn.Release();
				}
			}
			catch (Exception e)
			{
				if (!conn.isShutdown)
				{	
					logger.error("[{0}] Conn# {1} Error occurred when connecting to server. Error is: {2}",
						conn.serviceName, conn.connNumber, e);
					conn.Release();
				}
			}
			finally
			{
				conn = null;  //free reference to the object
			}
		}