63 lines
1.6 KiB
C#
63 lines
1.6 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Net;
|
|||
|
using System.Net.Sockets;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using OpenCvSharp;
|
|||
|
using STTech.BytesIO.Core;
|
|||
|
using STTech.BytesIO.Tcp;
|
|||
|
using TcpClient = STTech.BytesIO.Tcp.TcpClient;
|
|||
|
namespace HisenceYoloDetection
|
|||
|
{
|
|||
|
public class TCPClienDriver
|
|||
|
{
|
|||
|
private TcpClient client;
|
|||
|
public event Action<byte[]> OnClientDataReceived;
|
|||
|
public void Strart()
|
|||
|
{
|
|||
|
client = new TcpClient();
|
|||
|
client.Host = "192.168.3.100";
|
|||
|
client.Port= 9004;
|
|||
|
//client.Host = "127.0.0.1";
|
|||
|
//client.Port = 9000;
|
|||
|
client.Connect();
|
|||
|
|
|||
|
client.OnDataReceived += Client_OnDataReceived;
|
|||
|
client.OnConnectedSuccessfully += Client_OnConnectedSuccessfully;
|
|||
|
client.OnDisconnected += Client_OnDisconnected;
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void Client_OnDisconnected(object? sender, DisconnectedEventArgs e)
|
|||
|
{
|
|||
|
Console.WriteLine("已经断开");
|
|||
|
}
|
|||
|
|
|||
|
private void Client_OnConnectedSuccessfully(object? sender, ConnectedSuccessfullyEventArgs e)
|
|||
|
{
|
|||
|
Console.WriteLine("已经连上");
|
|||
|
}
|
|||
|
|
|||
|
private void Client_OnDataReceived(object? sender, DataReceivedEventArgs e)
|
|||
|
{
|
|||
|
OnClientDataReceived?.Invoke(e.Data);
|
|||
|
}
|
|||
|
private void Stop()
|
|||
|
{
|
|||
|
client.Disconnect();
|
|||
|
}
|
|||
|
|
|||
|
public void btnSendMsg(string msg)
|
|||
|
{
|
|||
|
//client.Send(msg.GetBytes("GBK"));
|
|||
|
client.Send(System.Text.Encoding.UTF8.GetBytes(msg));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|