예제 #1
0
    /// <summary>
    /// parse input data
    /// </summary>
    /// <param name="gameAction"></param>
    /// <param name="actionParam"></param>
    /// <param name="formater"></param>
    /// <param name="bShowLoading"></param>
    private void SocketRequest(GameAction gameAction, ActionParam actionParam, IHeadFormater formater, bool bShowLoading)
    {
        if (mSocket == null)
        {
            string   url = NetWriter.GetUrl();
            string[] arr = url.Split(new char[] { ':' });
            if (arr.Length != 2)
            {
                Debug.LogError("Url is error:" + url);
                return;
            }
            int nPort = int.Parse(arr[1]);
            mSocket = new SocketConnect(arr[0], nPort, formater);
        }
        gameAction.Head.MsgId = NetWriter.MsgId + 1;
        SocketPackage package = new SocketPackage();

        package.ActionId   = gameAction.ActionId;
        package.Action     = gameAction;
        package.HasLoading = bShowLoading;
        package.SendTime   = DateTime.Now;
        byte[] data = gameAction.Send(actionParam);
        NetWriter.resetData();
        if (bShowLoading)
        {
            RequestDelegate(Status.eStartRequest);
        }
        mSocket.Send(data, package);
    }
예제 #2
0
파일: TcpPeer.cs 프로젝트: kkzaikk/U3D_Net
    public bool SendPacket(int dest, int cmd, byte[] data)
    {
        if (_socketCon.isSocketNull())
        {
            return(false);
        }

        if (data != null && _socketCon.Send(data))
        {
            Debug.Log("发送消息 dest=" + dest + ",cmd=" + cmd + " 成功 !");
        }

        return(true);
    }
예제 #3
0
    /// <summary>
    /// parse input data
    /// </summary>
    /// <param name="gameAction"></param>
    /// <param name="actionParam"></param>
    /// <param name="formater"></param>
    /// <param name="bShowLoading"></param>
    private void SocketRequest(GameAction gameAction, ActionParam actionParam, IHeadFormater formater, bool bShowLoading)
    {
        if (mSocket == null)
        {
            string   strUrl = NetWriter.GetUrl();
            string[] arr    = strUrl.Split(new char[] { ':' });
            int      nPort  = int.Parse(arr[1]);
            mSocket = new SocketConnect(arr[0], nPort, formater);
            mSocket.PushCallback += OnPushCallback;
        }
        gameAction.Head.MsgId = NetWriter.MsgId - 1;

        SocketPackage package = new SocketPackage();

        package.MsgId      = gameAction.Head.MsgId;
        package.ActionId   = gameAction.ActionId;
        package.Action     = gameAction;
        package.HasLoading = bShowLoading;
        package.SendTime   = DateTime.Now;
        byte[] data = gameAction.Send(actionParam);
        NetWriter.resetData();
        if (bShowLoading)
        {
            RequestDelegate(Status.eStartRequest);
        }
        mSocket.Send(data, package);
    }
예제 #4
0
    /// <summary>
    /// Socket消息发送
    /// </summary>
    /// <param name="gameAction">消息id</param>
    /// <param name="boby">内容</param>
    /// <param name="formater">解析协议对象</param>
    /// <param name="bShowLoading">是否显示loading界面</param>
    private void SocketRequest(GameAction gameAction, byte [] boby, IHeadFormater formater, bool bShowLoading)
    {
        if (mSocket == null)
        {
            Debug.LogError("与服务器断开连接,由于服务器无响应");
            Close();
            QueueEvent(EventDef.ServerColsed);
            return;
            //string strUrl = NetWriter.GetUrl();
            //string[] arr = strUrl.Split(new char[] { ':' });
            //int nPort = int.Parse(arr[1]);
            //mSocket = new SocketConnect(arr[0], nPort, formater);
        }
        gameAction.Head.MsgId = NetWriter.MsgId;

        SocketPackage package = new SocketPackage();

        package.MsgId      = (int)gameAction.Head.MsgId;
        package.ActionId   = (int)gameAction.ActionId;
        package.Action     = gameAction;
        package.HasLoading = bShowLoading;
        package.SendTime   = DateTime.Now;
        byte[] data = gameAction.Send(boby);
        NetWriter.resetData();
        if (bShowLoading)
        {
            RequestDelegate(Status.eStartRequest);
        }
        mSocket.Send(data, package);
    }
예제 #5
0
        public async Task <int> Send(string command)
        {
            var buffers = Encoding.UTF8.GetBytes(command + "\r\n");

            SocketConnect.SendBufferSize = buffers.Length;
            SocketConnect.Send(buffers);
            return(await readReply());
        }
예제 #6
0
    private void SendBySocket()
    {
        //从消息队列中取一条消息数据
        MessageStruct message = SendreceiveManage.getInstance().getWillSendData();

        if (message != null && _socketCon.Send(message.body))
        {
            Debug.Log("发送消息 dest=" + message.dest + ",cmd=" + message.cmd + " 成功 !");
        }
    }
예제 #7
0
    private void SendBySocket()
    {
        int count = sendMemory.Count;

        if (count == 0)
        {
            return;
        }

        SendPBMsg smsg = sendMemory[0];

        if (_socketCon == null)
        {
            Connect();
        }

        if (_socketCon.Send(smsg.sendBody))
        {
            Debug.Log("发送消息 dest=" + smsg.dest + ",cmd=" + smsg.cmd + " 成功 !");
            sendMemory.RemoveAt(0);
        }
    }