Beispiel #1
0
        internal MpxWinClientSocket(MpxClientTransport transport,
                                    IPEndPoint remoteServer,
                                    ClientSite clientSite,
                                    MpxSocketReceiveAction <MpxClientTransport> receiveAction) : base(transport, remoteServer, clientSite, receiveAction)
        {
            m_Client = new TcpClient();
            m_Client.Connect(m_EndPoint);
            m_Socket = m_Client.Client;

            m_Client.NoDelay                = true;
            m_Client.LingerState.Enabled    = true;
            m_Client.LingerState.LingerTime = m_Transport.Binding.SocketLingerSec;


            m_Client.ReceiveBufferSize = m_Transport.Binding.ClientReceiveBufferSize;
            m_Client.SendBufferSize    = m_Transport.Binding.ClientSendBufferSize;

            m_Client.ReceiveTimeout = m_Transport.Binding.ClientReceiveTimeout;
            m_Client.SendTimeout    = m_Transport.Binding.ClientSendTimeout;


            //Send ClientSite right away
            m_SendChunk.Position = 0;
            var sz = m_ClientSite.Serialize(m_SendChunk);

            m_Client.GetStream().Write(m_SendChunk.GetBuffer(), 0, sz);
            //------------------


            m_RArgs            = new SocketState(m_Client.Client, m_ReceiveChunk.GetBuffer());
            m_RArgs.Completed += socketCallback;

            initiateReceive();
        }
Beispiel #2
0
 public override MpxClientSocket MakeClientSocket(MpxClientTransport transport,
                                                  IPEndPoint remoteServer,
                                                  ClientSite clientSite,
                                                  MpxSocketReceiveAction <MpxClientTransport> receiveAction)
 {
     return(new MpxWinClientSocket(transport, remoteServer, clientSite, receiveAction));
 }
Beispiel #3
0
 protected internal MpxClientSocket(MpxClientTransport transport,
                                    IPEndPoint remoteServer,
                                    ClientSite clientSite,
                                    MpxSocketReceiveAction <MpxClientTransport> receiveAction)
     : base(transport, remoteServer, clientSite, receiveAction)
 {
 }
Beispiel #4
0
 protected internal MpxServerSocket(MpxListener listener,
                                    IPEndPoint clientEndPoint,
                                    ClientSite clientSite,
                                    MpxSocketReceiveAction <MpxServerTransport> receiveAction
                                    ) : base(listener.Transport, clientEndPoint, clientSite, receiveAction)
 {
     m_Listener = listener;
     listener.Transport.ClientSiteConnected(this);
 }
Beispiel #5
0
        private void clientThreadSpin(object cli)   //executes in its own thread/Task
        {
            TcpClient client = null;

            try
            {
                client                        = (TcpClient)cli;
                client.NoDelay                = true;
                client.LingerState.Enabled    = true;
                client.LingerState.LingerTime = Transport.Binding.SocketLingerSec;

                client.ReceiveBufferSize = Transport.Binding.ServerReceiveBufferSize;
                client.SendBufferSize    = Transport.Binding.ServerSendBufferSize;

                client.ReceiveTimeout = Transport.Binding.ServerReceiveTimeout;
                client.SendTimeout    = Transport.Binding.ServerSendTimeout;



                var nets = client.GetStream();

                var ms = new MemoryStream();
                ms.SetLength(ClientSite.MAX_STREAM_BYTE_LEN);

                socketRead(nets, ms.GetBuffer(), 0, sizeof(short));

                var fsz = ms.ReadBEShort();
                if (fsz > ms.Length)
                {
                    throw new ProtocolException(StringConsts.GLUE_BAD_PROTOCOL_FRAME_ERROR +
                                                "ClientSite sz={0} bytes over limit{1}".Args(fsz, ms.Length), closeChannel: true);
                }

                socketRead(nets, ms.GetBuffer(), sizeof(short), fsz);
                ms.Position = sizeof(short);
                var cs = new ClientSite(ms);

                //this will register the site with transport and start the async receive
                var ss = new MpxWinServerSocket(this, client, cs, this.m_SocketReceiveAction);
            }
            catch (Exception error)
            {
                if (client != null)
                {
                    try{ client.Close(); } catch {}
                }

                Transport.Binding.WriteLog(
                    LogSrc.Server,
                    Log.MessageType.Error,
                    StringConsts.GLUE_CLIENT_THREAD_ERROR + error.ToMessageWithType(),
                    from: "MpxWinListener.clientThreadSpin",
                    exception: error);
            }
        }
Beispiel #6
0
 public clientSiteState(MpxServerTransport transport, ClientSite site)
 {
     this.Transport = transport;
     this.Site      = site;
     m_Sockets      = new List <MpxServerSocket>();
     OutQueues      = new ConcurrentQueue <ResponseMsg> [GENERATIONS];
     for (var i = 0; i < GENERATIONS; i++)
     {
         OutQueues[i] = new ConcurrentQueue <ResponseMsg>();
     }
 }
Beispiel #7
0
        internal MpxWinServerSocket(MpxListener listener,
                                    TcpClient client,
                                    ClientSite clientSite,
                                    MpxSocketReceiveAction <MpxServerTransport> receiveAction
                                    ) : base(listener, (IPEndPoint)client.Client.RemoteEndPoint, clientSite, receiveAction)
        {
            m_Client = client;
            m_Socket = m_Client.Client;

            m_RArgs            = new SocketState(m_Client.Client, m_ReceiveChunk.GetBuffer());
            m_RArgs.Completed += socketCallback;

            initiateReceive();
        }
Beispiel #8
0
        protected MpxSocket(TTransport transport,
                            IPEndPoint endPoint,
                            ClientSite clientSite,
                            MpxSocketReceiveAction <TTransport> receiveAction)
        {
            m_Transport     = transport;
            m_EndPoint      = endPoint;
            m_ClientSite    = clientSite;
            m_ReceiveAction = receiveAction;


            m_SendChunk    = ((IMpxTransport)transport).Binding.MakeOrReuseChunk();
            m_ReceiveChunk = ((IMpxTransport)transport).Binding.MakeOrReuseChunk();
        }
Beispiel #9
0
 MakeClientSocket(MpxClientTransport transport,
                  IPEndPoint remoteServer,
                  ClientSite clientSite,
                  MpxSocketReceiveAction <MpxClientTransport> receiveAction);