Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Hostname.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  16. * USA.
  17. */
  18. package com.tigervnc.rfb;
  19. public class Hostname {
  20. public static String getHost(String vncServerName) {
  21. int colonPos = vncServerName.indexOf(':');
  22. if (colonPos == 0)
  23. return "localhost";
  24. if (colonPos == -1)
  25. colonPos = vncServerName.length();
  26. return vncServerName.substring(0, colonPos);
  27. }
  28. public static int getPort(String vncServerName) {
  29. int colonPos = vncServerName.indexOf(':');
  30. if (colonPos == -1 || colonPos == vncServerName.length()-1)
  31. return 5900;
  32. if (vncServerName.charAt(colonPos+1) == ':') {
  33. return Integer.parseInt(vncServerName.substring(colonPos+2));
  34. }
  35. int port = Integer.parseInt(vncServerName.substring(colonPos+1));
  36. if (port < 100)
  37. port += 5900;
  38. return port;
  39. }
  40. }