Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        //executes in its own thread/Task
        private void clientThreadSpin(object cli)
        {
            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);
              }
        }