コード例 #1
0
    IEnumerator SendData()
    {
        int myId = GameManager.instance.myId;

        while (true)
        {
            yield return(ws);

            TransformVO vo      = new TransformVO(myId, transform.position, transform.rotation.eulerAngles);
            string      payload = JsonUtility.ToJson(vo);

            DataVO dataVO = new DataVO();
            dataVO.type    = "Transform";
            dataVO.payload = payload;
            SocketClient.instance.SendData(JsonUtility.ToJson(dataVO)); //json으로 변경해서 전송
        }
    }
コード例 #2
0
    private void ReceiveData(WebSocket sender, MessageEventArgs e)
    {
        DataVO vo = JsonUtility.FromJson <DataVO>(e.Data);

        IMsgHandler handler = handlerDictionary[vo.type];

        handler.HandleMsg(vo.payload);


        //굳이 리플렉션 안써도 딕셔너리로 충분히 해결가능
        // MethodInfo m = this.GetType().GetMethod($"{vo.type}Handler", BindingFlags.Instance | BindingFlags.NonPublic);

        // if(m == null){
        //     Debug.Log("에러 발생 정의되지 않은 타입");
        // }

        // m.Invoke(this, new object[]{vo.payload});
    }
コード例 #3
0
ファイル: Default.aspx.cs プロジェクト: wshcdr/AS3_NETWORK
    protected void Page_Load(object sender, EventArgs e)
    {
        byte[] byteData = null;
        try
        {
            if (context == null)
            {
                context = ContextUtil.getInstance(Server.MapPath("."));
                encrypt = context.getOuterEncrypt();
            }

            if (encoder == null)
            {
                encoder = ParamEncoder.getInstance();
            }
            if (decoder == null)
            {
                decoder = ParamDecoder.getInstance();
            }

            encoder.outEncoder = context.getOuterResolve();
            decoder.outDecoder = context.getOuterResolve();

            Stream input = Request.InputStream;

            if (input.CanRead)
            {
                byteData = new byte[input.Length];
                input.Read(byteData, 0, (int)input.Length);
                input.Close();
                input.Dispose();

                // 解密
                if (encrypt != null)
                {
                    byteData = encrypt.decrypt(byteData);
                }

                dataVo = decoder.decoder(byteData);
                Type serviceCls = context.getService(context.getServiceNameSpace() + "." + dataVo.ServiceName);

                MethodInfo method = serviceCls.GetMethod(dataVo.MethodName);

                object result = method.Invoke(System.Activator.CreateInstance(serviceCls), dataVo.Param);

                dataVo.Result       = result;
                dataVo.ResultStatus = "success";
                byte[] resultData = encoder.encode(dataVo);

                if (encrypt != null)
                {
                    resultData = encrypt.encrypt(resultData);
                }

                output = Response.OutputStream;
                output.Write(resultData, 0, resultData.Length);
                output.Flush();
                output.Close();
                output.Dispose();
            }
            else
            {
            }
        }
        catch (Exception exc)
        {
            if (dataVo == null && byteData != null)
            {
                dataVo = decoder.decoder(byteData);
            }
            if (dataVo == null)
            {
                dataVo = new DataVO();
            }
            dataVo.ResultStatus = "error";
            dataVo.ErrorMessage = exc.ToString();
            byte[] resultData = encoder.encode(dataVo);

            if (encrypt != null)
            {
                resultData = encrypt.encrypt(resultData);
            }
            output = Response.OutputStream;
            output.Write(resultData, 0, resultData.Length);
            output.Flush();
            output.Close();
            output.Dispose();
        }
    }