/// <summary>
 /// send quit command to server and close socket
 /// </summary>
 /// <param name="sock">the JavaSocket object</param>
 public static void closeSocket(JavaSocket sock)
 {
     byte[] header;
     header = packHeader(FDFS_PROTO_CMD_QUIT, 0, 0);
     sock.GetStream().Write(header, 0, header.Length);
     sock.Close();
 }
        /// <summary>
        /// send ACTIVE_TEST command to server, test if network is ok and the server is alive
        /// </summary>
        /// <param name="sock">the JavaSocket object</param>
        public static bool activeTest(JavaSocket sock)
        {
            byte[] header;
            header = packHeader(FDFS_PROTO_CMD_ACTIVE_TEST, 0, 0);
            sock.GetStream().Write(header, 0, header.Length);
            RecvHeaderInfo headerInfo = recvHeader(sock.GetStream(), TRACKER_PROTO_CMD_RESP, 0);

            return(headerInfo.errno == 0 ? true : false);
        }
        /// <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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
 /**
  * force close socket,
  */
 public void closeDirectly()
 {
     if (this.sock != null)
     {
         try
         {
             ProtoCommon.closeSocket(this.sock);
         }
         finally
         {
             this.sock = null;
         }
     }
 }
 /// <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);
     }
 }
Esempio n. 7
0
 public Connection(JavaSocket sock, InetSocketAddress inetSockAddr)
 {
     this.sock         = sock;
     this.inetSockAddr = inetSockAddr;
 }