public class GetSocket
{
private static Socket socket = new Socket();
private GetSocket()
{
super();
}
public synchronized static Socket getSocket()
{
Log.i("getSocket", "getSocket");
try
{
if (!socket.isConnected())
{
Log.i("ServerInfo", "ServerInfo.ip: "+ServerInfo.ip+"ServerInfo.port : "+ServerInfo.port);
socket.connect(new InetSocketAddress(ServerInfo.ip, ServerInfo.port), 15000);
}
}
catch (SocketTimeoutException e)
{
Log.e("8023", "连接服务器超时", e);
return null;
}
catch (IOException e)
{
Log.e("8023", "连接服务器错误", e);
return null;
}
return socket;
}
public static void close()
{
if (socket != null && socket.isConnected())
{
try
{
socket.close();
}
catch (IOException e)
{
Log.e("8023", "断开服务器错误", e);
}
}
}
}
{
private static Socket socket = new Socket();
private GetSocket()
{
super();
}
public synchronized static Socket getSocket()
{
Log.i("getSocket", "getSocket");
try
{
if (!socket.isConnected())
{
Log.i("ServerInfo", "ServerInfo.ip: "+ServerInfo.ip+"ServerInfo.port : "+ServerInfo.port);
socket.connect(new InetSocketAddress(ServerInfo.ip, ServerInfo.port), 15000);
}
}
catch (SocketTimeoutException e)
{
Log.e("8023", "连接服务器超时", e);
return null;
}
catch (IOException e)
{
Log.e("8023", "连接服务器错误", e);
return null;
}
return socket;
}
public static void close()
{
if (socket != null && socket.isConnected())
{
try
{
socket.close();
}
catch (IOException e)
{
Log.e("8023", "断开服务器错误", e);
}
}
}
}