最近有个小项目,需要调用装置的录波数据,使用tcp模式,在这里整理了下如何使用c#实现tcp连接并实现发送接收数据,分享出来。
我这里使用的tcpclient ,终端是tcpserver模式。
首先自定义一个类 clientsocket
class clientsocket //tcp客户端的类 增加一个client104类
{
public Socket newclient;
public bool Connected;
public Thread myThread;
public delegate void MyInvoke(string str);
public string send_str,receive_str;//发送字符串,接收字符串
public string stringdata="";
public int hexflag=1; //十六进制标志
public int sendlen = 0; //发送长度,用户每次发送的字节个数使用
private StringBuilder builder = new StringBuilder();
public byte[] buffer = new byte[4096];
public List<byte> data = new List<byte>();
/// <summary>
/// connect 网络连接
/// </summary>
/// <param name="ipadd"></param>
/
使用c#实现tcp的连接和发送接收数据
于 2021-04-23 10:45:53 首次发布