private void Server_OnReceive(int arg1, int arg2) { //int aaa = server.GetAttached<int>(arg1); //Console.WriteLine($"Pull已接收:{arg1} 长度:{arg2}"); byte[] data = server.Fetch(arg1, server.GetLength(arg1)); server.Send(arg1, data, 0, data.Length); }
private void Watcher_Created(object sender, FileSystemEventArgs e) { if (!File.Exists(jpgFile)) { return; } else { Thread.Sleep(5000); using (var fs = new FileStream(jpgFile, 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 = server.StructureToByte <PkgHeader>(header); // 组合最终发送的封包 (封包头+封包体) byte[] sendBytes = Utils.GetSendBuffer(headerBytes, bodyBytes); server.Send(ID, sendBytes, sendBytes.Length); } } count = 0; watcher.Created -= Watcher_Created; watcher.Dispose(); Utils.delDir(path + now); }
//Rvt导出为Ifc 事件 private void Uiapp_Idling(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e) { if (count != 0) { return; } if (File.Exists(rvtName)) { try { Document doc = uiapp.Application.OpenDocumentFile(rvtName); using (Transaction transaction = new Transaction(doc, "ifcexporter")) { transaction.Start(); IFCExportOptions opt = null; doc.Export(path, ifcName, opt); transaction.Commit(); } doc.Close(); return; } catch (Exception ex) { TaskDialog.Show("error", ex.ToString()); } finally { #region 发送生成的ifc if (File.Exists(rvtName.Replace(".rvt", ".ifc"))) { using (var fs = new FileStream(rvtName.Replace(".rvt", ".ifc"), 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 = server.StructureToByte <PkgHeader>(header); // 组合最终发送的封包 (封包头+封包体) byte[] sendBytes = GetSendBuffer(headerBytes, bodyBytes); server.Send(ID, sendBytes, sendBytes.Length); } delDir(path);//发送完成,删除文件 } else { TaskDialog.Show("", rvtName.Replace(".rvt", ".ifc")); } #endregion } count++; } }
private void Server_OnAccept(Guid obj) { //KKNetEngine.KKNet KKNet = new KKNetEngine.KKNet(); //server.SetAttached(obj, KKNet); //Console.WriteLine($"Pull已连接{obj}"); byte[] init_data = { 0x00, 0x01, 0x00, 0x01, 0x70, 0x06, 0x00, 0x00, 0x00, 0x01, 0x01 }; // 引擎初始化 server.InitKKNet(obj); server.Send(obj, init_data, 0, init_data.Length); CMD_MESSAGE_BOX cmd = new CMD_MESSAGE_BOX(); byte[] cmd_data = cmd.SetText("0\n欢迎进入KK开发服\nhttps://github.com/hnhhzy/KKGame\n", 0x19); server.Send(obj, cmd_data, 0, cmd_data.Length); }
private HandleResult AcceptPool(IntPtr connId) { try { string strAdvance = string.Empty; byte[] strCmd = new byte[0]; bool IsDisconnect = false; //是否强制断开客户端 string ip = string.Empty; ushort sport = 0; if (_server.GetRemoteAddress(connId, ref ip, ref sport)) { strAdvance = string.Format(" > [{0},OnAccept] -> PASS({1}:{2})", connId, ip.ToString(), sport); WriteDeviceLog.WriteLog("Log\\" + _name + "\\Accept客户端", strAdvance, Guid.NewGuid().ToString()); } else { strAdvance = string.Format(" > [{0},OnAccept] -> Server_GetClientAddress() Error", connId); WriteDeviceLog.WriteLog("Log\\" + _name + "\\Accept客户端", strAdvance, Guid.NewGuid().ToString()); } ClientInfo clientInfo = new ClientInfo(); clientInfo.ConnId = connId; clientInfo.IpAddress = ip; clientInfo.Port = sport; if (_server.SetExtra(connId, clientInfo) == false) { //给客户端连接加载连接参数失败,处理出错。 } //连接断开时要干掉客户端对象。不然会增长过大。 if (DicConnId.ContainsKey(connId.ToString())) { DicConnId[connId.ToString()] = StrDeviceId; } else { DicConnId.TryAdd(connId.ToString(), StrDeviceId); //客户端连接池 } //if (SpreadObject.ContainsKey(connId)) //{ // SpreadObject[connId] = new SpreadModel(); //} //else //{ // SpreadObject.TryAdd(connId, new SpreadModel());//客户端扩展对象池 //} Thread.Sleep(1500); if (Dic.ContainsKey(StrDeviceId)) { IResolve = Dic[StrDeviceId]; IResolve.OnLinkStart(connId.ToString(), ref SpreadObject, strAdvance, ref strCmd, ref IsDisconnect); //是否强制断开连接True:强制断开客户端 False 不执行断开操作 if (IsDisconnect) { return(HandleResult.Error); } if (strCmd.Length > 0) { if (_server.Send(connId, strCmd, strCmd.Length) == false) { WriteDeviceLog.WriteLog("Log\\" + _name + "\\OnConnect", " 应答没有发出去。strCmd:" + Encoding.Default.GetString(strCmd), Guid.NewGuid().ToString()); } } } InitServiceInfo(true); return(HandleResult.Ok); } catch (Exception ex) { WriteDeviceLog.WriteLog("Log\\" + _name + "\\Accept客户端", ex.ToString(), Guid.NewGuid().ToString()); return(HandleResult.Error); } finally { //InitMonitorService.AutoResetEvent.Set(); } }