void r() { if (watch.IsRunning == false) { watch.Start(); } else { ping = Convert.ToInt32(watch.ElapsedMilliseconds); watch.Stop(); watch.Reset(); } if (oldping != ping) { oldping = ping; Debug.WriteLine("Ping" + oldping.ToString()); } byte[] data; data = new byte[sock.Available]; // sock.BeginReceive(data, 0, data.Length, SocketFlags.None, read, data); Debug.WriteLine("Reecvied by Server : " + data.Length.ToString() + " bytes"); sock.Receive(data, data.Length, SocketFlags.None); using (PackFormatter f = new PackFormatter()) { try { f.Deserialize(data); OnRecevied(ip, f.flag, f.pack); } catch { } } GC.SuppressFinalize(data); }
void bRecevie(IAsyncResult result) { sock.EndReceive(result); using (PackFormatter p = new PackFormatter()) { p.Deserialize((byte[])result.AsyncState); OnDataRecevied(p.flag, p.pack); } }
void read(IAsyncResult result) { // serializer.Deserialize((byte[])result.AsyncState); sock.EndReceive(result); using (PackFormatter formatter = new PackFormatter()) { formatter.Deserialize((byte[])result.AsyncState); if (formatter.flag < 1000) { OnRecevied(ip, formatter.flag, formatter.pack); } } }
void _connect() { while (ReverseBoolean(c())) { } while (true) { if (sock.Connected == false && autoConnect == true) { while (ReverseBoolean(c())) { } } else { } if (cn != sock.Connected) { cn = sock.Connected; if (cn == true) { try { OnConnected(); } catch { } } else { try { OnDisconnected(); } catch { } } } if (sock.Available > 0) { try { if (asyncRead == false) { using (PackFormatter formatter = new PackFormatter()) { byte[] data; data = new byte[sock.Available]; sock.Receive(data, 0, data.Length, SocketFlags.None); formatter.Deserialize(data); try { OnDataRecevied(formatter.flag, formatter.pack); } catch { } GC.SuppressFinalize(data); } } else { Task.Run(() => { using (PackFormatter formatter = new PackFormatter()) { byte[] data; data = new byte[sock.Available]; sock.Receive(data, 0, data.Length, SocketFlags.None); formatter.Deserialize(data); try { OnDataRecevied(formatter.flag, formatter.pack); } catch { } GC.SuppressFinalize(data); } }); } } catch (Exception ex) { } } } }