Tag: Amp failed connection failed gevent ISS TCO [] Tee mod
public class Socketclientmanager
{
public delegate void Connectstateeventhandler ();
Public event Connectstateeventhandler connectedevent;//Connection succeeded
Public event Connectstateeventhandler disconnectedevent;//Connection failed
public delegate void Receivemsgeventhandler (byte[] order);
public event Receivemsgeventhandler Receivemsgevent;
static Socket _socket = null;
static IPEndPoint IEP = NULL;
static bool isconnecting = FALSE;
static bool isconnected = FALSE;
Public Socketclientmanager (string Strip,int port)
{
_socket = new Socket (addressfamily.internetwork, SocketType.Stream, protocoltype.tcp);
IPAddress IP = Ipaddress.parse (Strip.trim ());
IEP = new IPEndPoint (IP, Port);
}
public void Start ()
{
Isconnecting = true;
Thread t = new thread (Connect);
T.isbackground = true;
T.start ();
}
private void Connect ()
{
while (isconnecting)
{
Try
{
if (! Issocketconnected (_socket) && disconnectedevent! = null)
{
Disconnectedevent ();
IsConnected = false;
_socket = new Socket (addressfamily.internetwork, SocketType.Stream, protocoltype.tcp);
_socket. Connect (IEP);
Connectedevent ();
IsConnected = true;
Thread t = new thread (RECEIVEMSG);
T.isbackground = true;
T.start ();
}
}
Catch {}
Finally
{
Thread.Sleep (500);
}
}
}
private void Receivemsg ()
{
while (isconnected)
{
byte[] buffer = new BYTE[32];
int count = _socket. Receive (buffer);
if (Count > 0&&receivemsgevent! = null)
{
Receivemsgevent (buffer);
}
}
}
public void sendmsg (byte[] order)
{
_socket. Send (order, order. Length, Socketflags.none);
}
private bool Issocketconnected (Socket s)
{
Return! ((S.poll (Selectmode.selectread) && (s.available = = 0)) | |!s.connected);
}
}
C#socket Communication Client (connection status monitoring, drop-link reconnection)