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_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 object SetSocketType(Message msg) { Type type = msg.WParam as Type; if (type == null) { throw new ArgumentException("msg.WParam 参数必需为类的Type对象"); } m_socket = type.Assembly.CreateInstance(type.FullName) as JSocket; if (m_socket == null) { throw new ArgumentException("msg.WParam 参数必需为继续JSocket的类的Type对象"); } return null; }
public PacketSender(JSocket socket, byte[] buffer) { m_socket = socket; m_buffer = buffer; m_pkgQueue = new Queue(); 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 SocketConnecter(JSocket socket) { m_socket = socket; }
void m_socket_ConnectedSuccess(JSocket socket) { CreateAndSendMsg(NetMsg.Connected, null, socket); }
void m_socket_ConnectedFaild(JSocket socket) { CreateAndSendMsg(NetMsg.Errored, null, socket); }
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; 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) { cryptor.Encrypt(pkg.Buffer, pkg.Length); } len = pkg.CopyTo(data, count, dataOffset); 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(); } }