示例#1
0
        /// <summary>
        /// connect to server
        /// </summary>
        /// <returns> connected JavaSocket object</returns>
        public JavaSocket connect()
        {
            JavaSocket sock = new JavaSocket();

            sock.SetReuseAddress(true);
            sock.setSoTimeout(ClientGlobal.g_network_timeout);
            sock.Connect(new InetSocketAddress(ip_addr, port), ClientGlobal.g_connect_timeout);
            return(sock);
        }
        /// <summary>
        /// construct JavaSocket object
        /// </summary>
        /// <param name="ip_addr">ip address or hostname</param>
        /// <param name="port">port number</param>
        /// <returns> connected JavaSocket object</returns>
        public static JavaSocket getSocket(string ip_addr, int port)
        {
            JavaSocket sock = new JavaSocket();

            sock.SetReuseAddress(true);
            sock.SendTimeout = g_network_timeout;
            sock.Connect(ip_addr, port);
            return(sock);
        }
 /// <summary>
 /// create from InetSocketAddress
 /// </summary>
 /// <param name="socketAddress"></param>
 /// <returns></returns>
 public static Connection create(InetSocketAddress socketAddress)
 {
     try
     {
         JavaSocket sock = new JavaSocket();
         sock.SetReuseAddress(true);
         sock.setSoTimeout(ClientGlobal.g_network_timeout);
         sock.Connect(socketAddress, ClientGlobal.g_connect_timeout);
         return(new Connection(sock, socketAddress));
     }
     catch (Exception e)
     {
         throw new MyException("connect to server " + socketAddress.Address + ":" + socketAddress.Port + " fail, emsg:" + e.Message);
     }
 }