Beispiel #1
0
        public string eth_submitHashrate(string strHash, string strID)
        {
            string strCmd = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_submitHashrate\",\"params\":[\"" + strHash + "\",\"" + strID + "\"],\"id\":73}";

            byte[] rgCmd = Encoding.UTF8.GetBytes(strCmd);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_strUrl);

            request.ContentType   = "application/json";
            request.Method        = "POST";
            request.ContentLength = rgCmd.Length;
            Stream strm = request.GetRequestStream();

            strm.Write(rgCmd, 0, rgCmd.Length);
            strm.Close();

            HttpWebResponse response  = (HttpWebResponse)request.GetResponse();
            string          strStatus = response.StatusDescription;
            HttpStatusCode  status    = response.StatusCode;

            strm = response.GetResponseStream();
            string strContent = "";

            using (StreamReader sr = new StreamReader(strm))
            {
                strContent = sr.ReadToEnd();
            }

            SimpleJson.JsonObject json = SimpleJson.SimpleJson.DeserializeObject(strContent) as SimpleJson.JsonObject;
            if (json.Count == 3)
            {
                if (!verifyValue(json, "jsonrpc", "2.0"))
                {
                    return(json.ToString());
                }

                if (!verifyValue(json, "id", "73"))
                {
                    return(json.ToString());
                }

                bool?bResult = getValueAsBool(json, "result");
                if (bResult.HasValue)
                {
                    if (bResult.Value)
                    {
                        return("ACCEPTED");
                    }
                    else
                    {
                        return("REJECTED");
                    }
                }
            }

            return(json.ToString());
        }
        static int _m_ToString(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                SimpleJson.JsonObject gen_to_be_invoked = (SimpleJson.JsonObject)translator.FastGetCSObj(L, 1);



                {
                    string gen_ret = gen_to_be_invoked.ToString(  );
                    LuaAPI.lua_pushstring(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Beispiel #3
0
        private void OnDownloadMapAndVoiceData(object objData, ResponseData result)
        {
            ClientSocket cs  = null;
            SslAppData   sad = new SslAppData();

            try
            {
                SimpleJson.JsonObject jsonPathData = new SimpleJson.JsonObject();
                jsonPathData.Add("op", "UPLOAD_PATH_DATA");
                jsonPathData.Add("data", (string)objData);
                //jsonPathData.Add("data", "no actual data.");
                string strJsonText = jsonPathData.ToString();

                cs = Connect();
                if (cs == null)
                {
                    result.Code = ResponseData.RESP_SERVER_UNREACHABLE;
                    result.Msg  = TypeAndParameter.STR_CONNECT_WITH_SERVER_FAILED;
                    return;
                }

                // 发送数据
                sad.SetType(SslAppData.APP_TYPE_PLAIN_JSON);
                byte[] allBytes = System.Text.Encoding.Default.GetBytes(strJsonText);
                if (allBytes.Length > SslAppData.SSL_APP_CONTENT_MAX_SIZE)
                {
                    sad.SetFirst(true);
                    sad.SetLast(false);
                    sad.SetData(allBytes, 0, SslAppData.SSL_APP_CONTENT_MAX_SIZE);
                    cs.Send(sad);

                    sad.SetFirst(false);
                    int i = SslAppData.SSL_APP_CONTENT_MAX_SIZE;
                    while (i < allBytes.Length)
                    {
                        if (allBytes.Length - i <= SslAppData.SSL_APP_CONTENT_MAX_SIZE)
                        {
                            sad.SetLast(true);
                            sad.SetData(allBytes, i);
                            i += allBytes.Length - i;
                        }
                        else
                        {
                            sad.SetData(allBytes, i, SslAppData.SSL_APP_CONTENT_MAX_SIZE);
                            i += SslAppData.SSL_APP_CONTENT_MAX_SIZE;
                        }
                        cs.Send(sad);
                    }
                }
                else
                {
                    sad.SetData(allBytes);
                    //sad.SetData(System.Text.Encoding.UTF8.GetBytes(strJsonText));
                    cs.Send(sad);
                }

                // 接收数据
                cs.Recv(sad);
                byte[] jsonData = sad.GetData();
                //strJsonText = System.Text.Encoding.Default.GetString(jsonData);
                strJsonText = System.Text.Encoding.UTF8.GetString(jsonData);

                var rsp = (IDictionary <string, object>)SimpleJson.SimpleJson.DeserializeObject(strJsonText);
                if ("AE_SUCCESS" == (rsp["err"] as string))
                {
                    result.Code = ResponseData.RESP_SUCCESS;
                    result.Msg  = TypeAndParameter.STR_UPLOAD_PATH_DATA_FINISHED;
                }
                else
                {
                    result.Msg = rsp["msg"] as string;
                }
            }
            catch (Exception e)
            {
                XxdwDebugger.LogError(e.StackTrace);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Close();
                }
            }
        }