static void Main(string[] args) { dwgFile = args[0]; dwgPath = dwgFile.Replace(".dwg", "") + "\\"; pkgInfo.IsHeader = true; pkgInfo.Length = pkgHeaderSize; if (client.Connect("192.168.2.18", 1137) == true) { using (var fs = new FileStream(dwgFile, FileMode.Open)) { // 封包体 byte[] bodyBytes = new byte[fs.Length]; fs.Read(bodyBytes, 0, bodyBytes.Length); fs.Close(); // 封包头 PkgHeader header = new PkgHeader(); header.Id = ++id; header.BodySize = bodyBytes.Length; byte[] headerBytes = client.StructureToByte <PkgHeader>(header); // 组合最终发送的封包 (封包头+封包体) byte[] sendBytes = DwgUtils.GetSendBuffer(headerBytes, bodyBytes); client.Send(sendBytes, sendBytes.Length); } } client.OnClose += Client_OnClose; client.OnConnect += Client_OnConnect; client.OnReceive += Client_OnReceive; client.OnSend += Client_OnSend; System.Diagnostics.Process.GetCurrentProcess().WaitForExit(); }
public Pull(int receiveBufferSize, string ip, int port) { client = new TcpPullClient(receiveBufferSize); client.OnConnect += Client_OnConnect; client.OnReceive += Client_OnReceive; client.OnSend += Client_OnSend; client.OnClose += Client_OnClose; client.Connect(ip, port); }
private static void Connect(string ip, ushort port) { Task.Run(() => { while (!HClient.Connect(ip, port, false)) { if (IsExited) { break; } Thread.Sleep(1000); } }); }