com.baidu.driver4j.bns
类 SocketUtils

java.lang.Object
  继承者 com.baidu.driver4j.bns.SocketUtils

public class SocketUtils
extends Object

Utility tool class for Socket

从以下版本开始:
1.0.0
作者:
xiemalin

构造方法摘要
SocketUtils()
           
 
方法摘要
static void closeSocket(Socket socket)
          close socket safety
static Socket createSocket(String host, int port)
          Create a simple socket client instance with default connectionTimeout and soTimeout
static Socket createSocket(String host, int port, int connectionTimeout, int readTimeout)
          Create a simple socket client instance with connectionTimeout and soTimeout
static String getDottedIP(int ip)
          Convert integer IP to format of 'xxx.xx.xx.xx' string
static String getIpByHost(String host)
          get ip address by host name
static String hexStringIp2DottedIp(String ipHex)
          Convert Hex integer IP to format of 'xxx.xx.xx.xx' string
static boolean isSocketConnected(Socket socket)
          To check Socket instance if connected
static byte[] readSocket(Socket socket)
           
static void writeSocket(Socket socket, byte[] message)
          Write bytes to socket
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

SocketUtils

public SocketUtils()
方法详细信息

getDottedIP

public static String getDottedIP(int ip)
Convert integer IP to format of 'xxx.xx.xx.xx' string

参数:
ip - IP of integer
返回:
formated IP String

hexStringIp2DottedIp

public static String hexStringIp2DottedIp(String ipHex)
Convert Hex integer IP to format of 'xxx.xx.xx.xx' string

参数:
ipHex - IP of hex integer
返回:
formated IP String

getIpByHost

public static String getIpByHost(String host)
get ip address by host name

参数:
host - name
返回:
ip address or null if host name not found

createSocket

public static Socket createSocket(String host,
                                  int port)
                           throws IOException
Create a simple socket client instance with default connectionTimeout and soTimeout

参数:
host - remote host name
port - remote port
返回:
Socket instance
抛出:
IOException - if an I/O error occurs when creating the socket.

createSocket

public static Socket createSocket(String host,
                                  int port,
                                  int connectionTimeout,
                                  int readTimeout)
                           throws IOException
Create a simple socket client instance with connectionTimeout and soTimeout

参数:
host - remote host name
port - remote port
connectionTimeout -
readTimeout -
返回:
抛出:
IOException - if an I/O error occurs when creating the socket.

closeSocket

public static void closeSocket(Socket socket)
close socket safety

参数:
socket - Socket instance

isSocketConnected

public static boolean isSocketConnected(Socket socket)
To check Socket instance if connected

参数:
socket - Socket instance
返回:
true if socket is connected. otherwise return false

writeSocket

public static void writeSocket(Socket socket,
                               byte[] message)
                        throws IOException
Write bytes to socket

参数:
socket - Socket instance
message - message to write out
抛出:
IOException - if an I/O error occurs when creating the socket.

readSocket

public static byte[] readSocket(Socket socket)
                         throws IOException
抛出:
IOException


Copyright © 2016. All rights reserved.