ServerInfo.java 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Copyright (C) 2008 Happy Fish / YuQing
  3. * <p>
  4. * FastDFS Java Client may be copied only under the terms of the GNU Lesser
  5. * General Public License (LGPL).
  6. * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
  7. */
  8. package com.kmall.common.fileserver.fastdfs;
  9. import java.io.IOException;
  10. import java.net.InetSocketAddress;
  11. import java.net.Socket;
  12. /**
  13. * Server Info
  14. *
  15. * @author Happy Fish / YuQing
  16. * @version Version 1.7
  17. */
  18. public class ServerInfo {
  19. protected String ip_addr;
  20. protected int port;
  21. /**
  22. * Constructor
  23. *
  24. * @param ip_addr address of the server
  25. * @param port the port of the server
  26. */
  27. public ServerInfo(String ip_addr, int port) {
  28. this.ip_addr = ip_addr;
  29. this.port = port;
  30. }
  31. /**
  32. * return the ip address
  33. *
  34. * @return the ip address
  35. */
  36. public String getIpAddr() {
  37. return this.ip_addr;
  38. }
  39. /**
  40. * return the port of the server
  41. *
  42. * @return the port of the server
  43. */
  44. public int getPort() {
  45. return this.port;
  46. }
  47. /**
  48. * connect to server
  49. *
  50. * @return connected Socket object
  51. */
  52. public Socket connect() throws IOException {
  53. Socket sock = new Socket();
  54. sock.setReuseAddress(true);
  55. sock.setSoTimeout(ClientGlobal.g_network_timeout);
  56. sock.connect(new InetSocketAddress(this.ip_addr, this.port), ClientGlobal.g_connect_timeout);
  57. return sock;
  58. }
  59. }