Пример использования:
---------------------
private void button1_Click(object sender, EventArgs e)
{
Thread _thr = new Thread(_thr_process);
_thr.IsBackground = false;
_thr.Start();
}
CustomSocket socket;
private void event_socket_rx_data(byte[] msg)
{
log.log_rx(msg);
}
{
log.log_rx(msg);
}
private void event_socket_tx_data(byte[] msg)
{
log.log_tx(msg);
}
{
log.log_tx(msg);
}
private void event_socket_connect(string msg)
{
log.log_msg(msg);
}
{
log.log_msg(msg);
}
private void event_socket_noconnect(string msg)
{
log.log_err(msg);
}
{
log.log_err(msg);
}
private void event_socket_close_connect(string msg)
{
log.log_msg(msg);
}
{
log.log_msg(msg);
}
private void _thr_process()
{
socket = new CustomSocket();
socket.event_rx = event_socket_rx_data;
socket.event_tx = event_socket_tx_data;
socket.event_close_connection = event_socket_close_connect;
socket.event_connection = event_socket_connect;
socket.event_noconnection = event_socket_noconnect;
{
socket = new CustomSocket();
socket.event_rx = event_socket_rx_data;
socket.event_tx = event_socket_tx_data;
socket.event_close_connection = event_socket_close_connect;
socket.event_connection = event_socket_connect;
socket.event_noconnection = event_socket_noconnect;
if (!socket.doConnect("192.168.0.209", 5205))
return;
socket.Send(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }));
rx_bytes = new byte[1024];
socket.Receive(ref rx_bytes, 0, 1024, 2000);
socket.CloseConnection();
}
Скачать класс: CustomSocket.cs