public void Close() { IsActive = false; if (socket != null && socket.Connected) { socket.Close(); } if (client != null && client.Connected) { client.Close(); } send = null; receive = null; onClose?.Invoke(this); sendQueue = new ConcurrentQueue <qLuaPacket>(); receiveQueue = new ConcurrentQueue <qLuaPacket>(); DynValue OnClose = luaTable.Get("OnClose"); if (OnClose.Function != null) { OnClose.Function.Call(luaTable); } else { plugin.log.Info("qlay->socket", "Connection closed"); } SocketConnections.ConnectionRemove(this); }
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); }