37 lines
962 B
37 lines
962 B
using System;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
|
|
namespace SSWMS.Server
|
|
{
|
|
public class ClientSocket : BaseSocket
|
|
{
|
|
public ClientSocket(string ip, int port) : base(null)
|
|
{
|
|
RemoteIP = ip;
|
|
RemotePort = port;
|
|
}
|
|
|
|
public bool Connect(out string sResult)
|
|
{
|
|
bool bResult = true;
|
|
sResult = string.Empty;
|
|
try
|
|
{
|
|
if (_socket == null || !_socket.Connected)
|
|
{
|
|
Dispose();
|
|
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
|
_socket.Connect(IPAddress.Parse(RemoteIP), RemotePort);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
bResult = false;
|
|
sResult = ex.Message;
|
|
Dispose();
|
|
}
|
|
return bResult;
|
|
}
|
|
}
|
|
}
|