public qLuaPacket() { if (stream == null) { stream = new qStream(new MemoryStream()); } }
public qLuaPacket(uint id) { if (id != 0) { this.id = id; } if (stream == null) { stream = new qStream(new MemoryStream()); } }
public void ServerConnect(TcpClient client) { IsActive = true; this.client = client; if (client.Connected) { socket = client.Client; stream = new qStream(client.GetStream()); send = new Thread(SendThread); receive = new Thread(ReceiveThread); send.Start(); receive.Start(); } }
public bool Connect(string host, int port) { IsActive = true; client = new TcpClient(); try { client.Connect(host, port); if (client.Connected) { socket = client.Client; stream = new qStream(client.GetStream()); send = new Thread(SendThread); receive = new Thread(ReceiveThread); send.Start(); receive.Start(); SocketConnections.ConnectionAdd(this); return(true); } } catch (Exception ex) { DynValue OnError = luaTable.Get("OnError"); if (OnError.Function != null) { OnError.Function.Call(luaTable, ex.Message); } else { plugin.log.Info("qlay->socket", "Connection error: " + ex.Message); } } return(false); }
public void ProcessIncomingPacket() { if (IsActive && socket != null && socket.Connected) { if (receiveQueue.Count > 0) { for (int i = 0; i < 200 && receiveQueue.Count > 0; i++) { qLuaPacket packet; if (receiveQueue.TryDequeue(out packet)) { try { MemoryStream memoryStream = new MemoryStream(packet.data); qStream stream = new qStream(memoryStream); packet.stream = stream; DynValue OnReceive = luaTable.Get("OnReceive"); if (OnReceive.Function != null) { OnReceive.Function.Call(luaTable, packet); } else { plugin.log.Info("qlay->socket", "Packet receive id: " + packet.id); } } catch (Exception ex) { plugin.log.Info("qlay->socket", "Read net msg " + ex.Message); Close(); } } } } } }