Esempio n. 1
0
        public Protocol(IGateClient sc)
        {
            _client = sc;

            var loader = new ProtocolLoader();

            _rpc = loader.CreateRpcProto();
        }
Esempio n. 2
0
        public static void Init(int session, string secret)
        {
            _session = session;
            _secret  = Encoding.UTF8.GetBytes(secret);

            var loader = new ProtocolLoader();

            _rpc = loader.CreateBattleProto();
        }
Esempio n. 3
0
	public void Run () {
        SpTypeManager server_tm = SpTypeManager.Import (server_proto);

        server = SpRpc.Create (server_tm, "package");

        client = SpRpc.Create (client_proto, "package");
        client.Attach (server_tm);

        TestFoobar ();
        TestFoo ();
        TestBar ();
        TestBlackhole ();
	}
Esempio n. 4
0
        public Protocol(IGateClient sc, Socket socket)
        {
            _client      = sc;
            _transporter = new Transporter(socket, this)
            {
                onDisconnect = Disconnect
            };
            _transporter.Start();

            var loader = new ProtocolLoader();

            _rpc = loader.CreateRpcProto();
        }
Esempio n. 5
0
    public void Run()
    {
        SpTypeManager server_tm = SpTypeManager.Import(server_proto);

        server = SpRpc.Create(server_tm, "package");

        client = SpRpc.Create(client_proto, "package");
        client.Attach(server_tm);

        TestFoobar();
        TestFoo();
        TestBar();
        TestBlackhole();
    }
Esempio n. 6
0
	public void Run () {
        IPAddress ip = IPAddress.Parse ("127.0.0.1");
		mSocket.Connect(new IPEndPoint(ip, 8888));

        mRpc = SpRpc.Create (s2c, "package");
        mRpc.Attach (c2s);

		Send ("handshake", null);
		Send ("set", new SpObject (SpObject.ArgType.Table, 
		                           "what", "hello", 
		                           "value", "world"));

		mSocket.BeginReceive (mRecvBuffer, 0, mRecvBuffer.Length, SocketFlags.None, new AsyncCallback(ReadCallback), this);
	}
Esempio n. 7
0
    public void Run()
    {
        IPAddress ip = IPAddress.Parse("127.0.0.1");

        mSocket.Connect(new IPEndPoint(ip, 8888));

        mRpc = SpRpc.Create(s2c, "package");
        mRpc.Attach(c2s);

        Send("handshake", null);
        Send("set", new SpObject(SpObject.ArgType.Table,
                                 "what", "hello",
                                 "value", "world"));

        mSocket.BeginReceive(mRecvBuffer, 0, mRecvBuffer.Length, SocketFlags.None, new AsyncCallback(ReadCallback), this);
    }
Esempio n. 8
0
    public static SpRpc Create(SpTypeManager tm, string package)
    {
        if (tm == null)
        {
            return(null);
        }

        SpType t = tm.GetType(package);

        if (t == null)
        {
            return(null);
        }

        SpRpc rpc = new SpRpc(tm, t);

        return(rpc);
    }
Esempio n. 9
0
        private SpRpc CreateProto(string subDir)
        {
            SpTypeManager c2SMgr;
            SpTypeManager s2CMgr;

            var c2S = _path + subDir + "/c2s.sproto";

            using (var stream = new FileStream(c2S, FileMode.Open)) {
                c2SMgr = SpTypeManager.Import(stream);
            }

            var s2C = _path + subDir + "/s2c.sproto";

            using (var stream = new FileStream(s2C, FileMode.Open)) {
                s2CMgr = SpTypeManager.Import(stream);
            }

            var rpc = SpRpc.Create(s2CMgr, "package");

            rpc.Attach(c2SMgr);
            return(rpc);
        }
Esempio n. 10
0
        public bool Start(string serverIP, short port, string packageName, string s2c, string c2s)
        {
            bool result = true;

            try
            {
                mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                IPAddress  ipAddress  = IPAddress.Parse(serverIP);
                IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, port);
                mSocket.ReceiveBufferSize = MAX_BUFFER_SIZE;
                mSocket.NoDelay           = true;

                mSocket.BeginConnect(ipEndPoint, new AsyncCallback(ConnectCallback), mSocket);
                if (mConnTimeoutEvent.WaitOne(MAX_CONNECT_TIME, false))
                {
                    if (mSocket.Connected)
                    {
                        mRpc = SpRpc.Create(s2c, packageName);
                        mRpc.Attach(c2s);

                        mSocket.BeginReceive(mReceiveBuffer, 0, mReceiveBuffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), this);
                    }
                }
                else
                {
                    // Block time out and do not recevie any signal
                    DebugHelper.Log("Block time out and do not recevie any signal");
                }
            }
            catch (Exception ex)
            {
                DebugHelper.Log(ex.ToString());

                result = false;
            }

            return(result);
        }
Esempio n. 11
0
        public bool Start(string serverIP, short port, string packageName, string s2c, string c2s)
        {
            bool result = true;

            try
            {
                mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                IPAddress ipAddress = IPAddress.Parse(serverIP);
                IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, port);
                mSocket.ReceiveBufferSize = MAX_BUFFER_SIZE;
                mSocket.NoDelay = true;

                mSocket.BeginConnect(ipEndPoint, new AsyncCallback(ConnectCallback), mSocket);
                if (mConnTimeoutEvent.WaitOne(MAX_CONNECT_TIME, false))
                {
                    if (mSocket.Connected)
                    {
                        mRpc = SpRpc.Create(s2c, packageName);
                        mRpc.Attach(c2s);

                        mSocket.BeginReceive(mReceiveBuffer, 0, mReceiveBuffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), this);
                    }
                }
                else
                {
                    // Block time out and do not recevie any signal
                    DebugHelper.Log("Block time out and do not recevie any signal");
                }
            }
            catch(Exception ex)
            {
                DebugHelper.Log(ex.ToString());

                result = false;
            }

            return result;
        }
Esempio n. 12
0
    public static SpRpc Create (SpTypeManager tm, string package) {
        if (tm == null)
            return null;

        SpType t = tm.GetType (package);
        if (t == null)
            return null;

        SpRpc rpc = new SpRpc (tm, t);
        return rpc;
    }
Esempio n. 13
0
	public void Run () {
        mRpc = SpRpc.Create (s2c, "package");
        mRpc.Attach (c2s);

		Send ("handshake", null);
		Send ("set", new SpObject (SpObject.ArgType.Table, 
		                           "what", "hello", 
		                           "value", "world"));

		mSocket.BeginReceive (mRecvBuffer, 0, mRecvBuffer.Length, SocketFlags.None, new AsyncCallback(ReadCallback), this);
	}