public PacketReader(JSocket socket, byte[] buffer) { m_socket = socket; m_buffer = buffer; ConfigPkg = m_socket.UsedPacket; m_cryptor = m_socket.ReceiveCryptor; if (m_cryptor == null) m_cryptor = new NoneCryptor(); m_receiveAsyncEvent = new SocketAsyncEventArgs(); m_receiveAsyncEvent.Completed += new EventHandler<SocketAsyncEventArgs>(receiveAsyncEvent_Completed); }
public PacketSender(JSocket socket, byte[] buffer) { m_socket = socket; m_buffer = buffer; m_pkgQueue = new Queue(); m_cryptorBuffer = new byte[m_buffer.Length]; m_cryptor = m_socket.SendCryptor; if (m_cryptor == null) m_cryptor = new NoneCryptor(); m_sendAsyncEvent = new SocketAsyncEventArgs(); m_sendAsyncEvent.UserToken = this; m_sendAsyncEvent.SetBuffer(m_buffer, 0, 0); m_sendAsyncEvent.Completed += new EventHandler<SocketAsyncEventArgs>(sendAsyncEvent_Completed); }
private static void sendAsyncImp(object state) { PacketSender ps = state as PacketSender; JSocket socket = ps.m_socket; try { sendAsyncEvent_Completed(socket.Socket, ps.m_sendAsyncEvent); } catch (Exception ex) { log.Error("Async send package error.", ex); socket.Disconnect(); } }
public PacketReader(JSocket socket, byte[] buffer) { m_socket = socket; m_buffer = buffer; ConfigPkg = m_socket.UsedPacket; m_cryptor = m_socket.ReceiveCryptor; if (m_cryptor == null) { m_cryptor = new NoneCryptor(); } m_receiveAsyncEvent = new SocketAsyncEventArgs(); m_receiveAsyncEvent.Completed += new EventHandler <SocketAsyncEventArgs>(receiveAsyncEvent_Completed); }
public PacketSender(JSocket socket, byte[] buffer) { m_socket = socket; m_buffer = buffer; m_pkgQueue = new Queue(); m_cryptorBuffer = new byte[m_buffer.Length]; m_cryptor = m_socket.SendCryptor; if (m_cryptor == null) { m_cryptor = new NoneCryptor(); } m_sendAsyncEvent = new SocketAsyncEventArgs(); m_sendAsyncEvent.UserToken = this; m_sendAsyncEvent.SetBuffer(m_buffer, 0, 0); m_sendAsyncEvent.Completed += new EventHandler <SocketAsyncEventArgs>(sendAsyncEvent_Completed); }
public SocketAccepter(JSocket socket) { m_socket = socket; }
private static void sendAsyncEvent_Completed(object sender, SocketAsyncEventArgs e) { PacketSender ps = (PacketSender)e.UserToken; JSocket socket = ps.m_socket; Queue q = ps.m_pkgQueue; byte[] cryptorBuffer = ps.m_cryptorBuffer; IPacketCryptor cryptor = ps.m_cryptor; int sended = e.BytesTransferred; byte[] data = ps.m_buffer; int count = ps.m_sendingLength - sended; if (count > 0) { Array.Copy(data, sended, data, 0, count); } else { count = 0; } e.SetBuffer(0, 0); int dataOffset = ps.m_lastPkgReadOffset; try { lock (q.SyncRoot) { while (q.Count > 0) { Packet pkg = (Packet)q.Peek(); int len = 0; if (dataOffset == 0) { System.Buffer.BlockCopy(pkg.Buffer, 0, cryptorBuffer, 0, pkg.Length); cryptor.Encrypt(cryptorBuffer, pkg.Length); } len = ByteArray.CopyTo(cryptorBuffer, dataOffset, data, count, pkg.Length); dataOffset += len; count += len; if (pkg.Length <= dataOffset) { q.Dequeue(); dataOffset = 0; //cryptor.Decrypt(pkg.Buffer, pkg.Length); cryptor.Update(); } if (data.Length == count) { break; } } ps.m_lastPkgReadOffset = dataOffset; if (count <= 0) { ps.m_sendingTcp = false; return; } } ps.m_sendingLength = count; e.SetBuffer(0, count); if (socket.Socket.SendAsync(e) == false) { sendAsyncEvent_Completed(sender, e); } } catch (Exception ex) { log.Error("Async sending package error.", ex); socket.Disconnect(); } }
void m_socket_ConnectedSuccess(JSocket socket) { OnConnected(true); }
void m_socket_ConnectedFaild(JSocket socket) { OnConnected(false); }
public SocketConnecter(JSocket socket) { m_socket = socket; }