Esempio n. 1
0
            bool PushDataToXMLParserStream()
            {
                lock (Client)
                {
                    try
                    {
                        int Available = Client.Available;
                        if (Available == 0)
                        {
                            return(false);
                        }

                        int NrToGet = IsConnectedViaTLS ? ReceiveBuffer.Length : Available;
                        NrToGet = Math.Min(NrToGet, ReceiveBuffer.Length);
                        int NrGot = 0;

                        do
                        {
                            NrGot = ActiveStream.Read(ReceiveBuffer, 0, NrToGet);
                            if (NrGot < 1)
                            {
                                break;
                            }
                            TotalDataReceivedInXmlMode.Add(NrGot);


                            byte[] DataToSend = new byte[NrGot];
                            Buffer.BlockCopy(ReceiveBuffer, 0, DataToSend, 0, NrGot);

                            lock (IncomingData)
                            {
                                if (DebugLevel >= 2)
                                {
                                    string PushData = Encoding.UTF8.GetString(DataToSend);
                                    Log(4, "Push Data to XmlStream: {0}", PushData);
                                }
                                XMLStream.PushData(DataToSend);
                            }
                        }while (NrGot == NrToGet && IsConnectedViaTLS);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log(3, "OnDisconnect in PushData: {0}", e.ToString());
                        if (OnDisconnect == null)
                        {
                            OnDisconnect.Invoke();
                        }
                        return(false);
                    }
                }
            }
Esempio n. 2
0
 protected override void OnDisable()
 {
     //Custom callback before shutdown
     OnPreDisconnect?.Invoke();
     PhotonNetwork.RemoveCallbackTarget(this);
     base.OnDisable();
 }
 private void DoDisconnect()
 {
     disconnectCallback?.Invoke(this);
     socket.Close();
     OnDisconnect();
 }