예제 #1
0
 public static void Main()
 {
     Console.WriteLine(" [x] Requesting fib(30)");
     using (RPCClient rpcClient = new RPCClient()) {
         string response = rpcClient.Call("30");
         Console.WriteLine(" [.] Got '{0}'", response);
     }
 }
예제 #2
0
    public static void Main()
    {
        var rpcClient = new RPCClient();

        Console.WriteLine(" [x] Requesting fib(30)");
        var response = rpcClient.Call("30");
        Console.WriteLine(" [.] Got '{0}'", response);

        rpcClient.Close();
    }
예제 #3
0
    public static void Main( string[] args )
    {
        var rpcClient = new RPCClient();

        var n = args.Length > 0 ? args[0] : "30";
        Console.WriteLine( " [x] Requesting fib({0})", n );
        var response = rpcClient.Call( n );
        Console.WriteLine( " [.] Got '{0}'", response );

        rpcClient.Close();

        Console.WriteLine( " Press [enter] to exit." );
        Console.ReadLine();
    }
예제 #4
0
파일: Program.cs 프로젝트: gezidan/ZYSOCKET
 static void Main(string[] args)
 {
     RPCClient client = new RPCClient();
     if (client.Connection("127.0.0.1", 3000))
     {
         client.Disconn += Client_Disconn;
         client.MsgOut += Client_MsgOut;
         client.RegModule(new Client());
         Console.Write("输入你的昵称:");
         if (client.Call<TalkService, bool>(p => p.IsLogIn(Console.ReadLine())))
         {
             while (true)
             {                       
                 string msg = Console.ReadLine();
                 client.Call<TalkService>(p => p.SendALL(msg));
               
             }
         }
     }
 }
예제 #5
0
파일: Program.cs 프로젝트: gezidan/ZYSOCKET
        static void Main(string[] args)
        {
            RPCClient client = new RPCClient();
            if (client.Connection("127.0.0.1", 3000))
            {
                client.OutTime = 10000000;
                client.Disconn += Client_Disconn;
                client.MsgOut += Client_MsgOut;
                client.RegModule(new Client());
                Console.Write("输入你的昵称:");

                var IServer = client.GetRPC<TalkService>();

                if (IServer.IsLogIn(Console.ReadLine()))
                {
                    while (true)
                    {                       
                        string msg = Console.ReadLine();
                        IServer.SendALL(msg);
                    
                    }
                }
            }
        }
예제 #6
0
파일: Program.cs 프로젝트: gezidan/ZYSOCKET
        static void Main(string[] args)
        {


            RPCClient client = new RPCClient();
            if (client.Connection("127.0.0.1", 9952))
            {
                client.OutTime = 2000;
                client.Disconn += Client_Disconn;
                client.RegModule(new ClientCall());

                Console.WriteLine("input userName:"******"123123")))
                {
                    Console.WriteLine("LogOn Is OK");

                    while (true)
                    {
                        string msg = Console.ReadLine();

                        client.Call<ServerClass>(p => p.SendAll(msg));


                        DateTime time = client.Call<ServerClass, DateTime>(p => p.GetServerTime());

                        Console.WriteLine("Serve time is " + time);

                        int value = 0;

                        client.Call<ServerClass>(p => p.OutRandom(out value));

                        Console.WriteLine("Random value is " + value);

                        Data x = new Data()
                        {
                            Name = "II",
                            Value = 0
                        };

                        var v = client.Call<ServerClass, Data>(p => p.Return(x));

                        Console.WriteLine("Data Name " + v.Name);

                        var l = client.Call<ServerClass, int>(p => p.RecComputer(10)); //这叫递归吗? 代价太大,深度最好别超过5层 实在没办法记得设置outtime

                        Console.WriteLine("Rec computer value:" + l);

                        var server = client.GetRPC<ServerClass>();

                        var ary = server.array(new string[] { "123", "123" }); //Array + string


                        System.Diagnostics.Stopwatch stop = new System.Diagnostics.Stopwatch();
                        stop.Start();
                        //int j = 0;
                        for (int i = 0; i < 10000; i++)
                        {
                            x=server.Return(x);
                        }
                        stop.Stop();
                        Console.WriteLine("Time:" + stop.ElapsedMilliseconds + " J:" + x.Value);



                    }

                }

            }

        }
예제 #7
0
#pragma warning disable IDE1006 // Naming Styles

        public static async Task Main(string[] args)
#pragma warning restore IDE1006 // Naming Styles
        {
            try
            {
                Logger.InitializeDefaults(Path.Combine(Global.Instance.DataDir, "Logs.txt"));
                Logger.LogStarting("Wasabi Backend");

                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;
                var configFilePath = Path.Combine(Global.Instance.DataDir, "Config.json");
                var config         = new Config(configFilePath);
                await config.LoadOrCreateDefaultFileAsync();

                Logger.LogInfo <Config>("Config is successfully initialized.");

                var roundConfigFilePath = Path.Combine(Global.Instance.DataDir, "CcjRoundConfig.json");
                var roundConfig         = new CcjRoundConfig(roundConfigFilePath);
                await roundConfig.LoadOrCreateDefaultFileAsync();

                Logger.LogInfo <CcjRoundConfig>("RoundConfig is successfully initialized.");

                var rpc = new RPCClient(
                    credentials: RPCCredentialString.Parse(config.BitcoinRpcConnectionString),
                    network: config.Network);

                await Global.Instance.InitializeAsync(config, roundConfig, rpc);

                try
                {
                    Directory.CreateDirectory(UnversionedWebBuilder.UnversionedFolder);
                    UnversionedWebBuilder.CreateDownloadTextWithVersionHtml();
                    UnversionedWebBuilder.CloneAndUpdateOnionIndexHtml();

                    if (File.Exists(Global.Instance.Coordinator.CoinJoinsFilePath))
                    {
                        string[] allLines = File.ReadAllLines(Global.Instance.Coordinator.CoinJoinsFilePath);
                        Last5CoinJoins = allLines.TakeLast(5).Reverse().ToList();
                        UnversionedWebBuilder.UpdateCoinJoinsHtml(Last5CoinJoins);
                    }

                    Global.Instance.Coordinator.CoinJoinBroadcasted += Coordinator_CoinJoinBroadcasted;
                }
                catch (Exception ex)
                {
                    Logger.LogWarning(ex, nameof(Program));
                }

                var endPoint = "http://localhost:37127/";

                using (var host = WebHost.CreateDefaultBuilder(args)
                                  .UseStartup <Startup>()
                                  .UseUrls(endPoint)
                                  .Build())
                {
                    await host.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Logger.LogCritical <Program>(ex);
            }
            // Note: Don't do finally here. Dispose in Startup.cs.
        }
예제 #8
0
        private static void Main(string[] args)
        {
            // get internal litedb database filename from app settings
            var databaseFileName = ConfigurationManager.AppSettings["LiteDBFileName"];

            // init the database
            Database = new DatabaseConsumer(databaseFileName);
            // get saved subscriptions
            Subscriptions = Database.GetSubscriptions().ToList();

            // get RPC connection params from app settings
            var rpcURL      = ConfigurationManager.AppSettings["RPCURI"];
            var rpcUsername = ConfigurationManager.AppSettings["RPCUsername"];
            var rpcPassword = ConfigurationManager.AppSettings["RPCPassword"];

            // init RPC connection
            RPCClient = new RPCClient(new Uri(rpcURL), rpcUsername, rpcPassword);
            // get info for the last block that was processed
            var lastBlock  = Database.GetLastBlock();
            var blockCount = RPCClient.GetBlockCount();

            // write out of the current block height, and last processed block height
            Console.Write("Current block: " + blockCount + ". " + (lastBlock == null ? " No previous block data found." : " Last block processed: " + lastBlock.Height));
            // if we already have block data, fetch transactions since the last seen block
            if (lastBlock != null && lastBlock.Height < blockCount)
            {
                Console.WriteLine(". processing " + (blockCount - lastBlock.Height) + " blocks...");
                // record how long it takes to process the block data
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                // look at all blocks from the last block that was processed until the current height
                for (var blockIndex = lastBlock.Height; blockIndex <= blockCount; blockIndex++)
                {
                    // fetch raw block data by height
                    var blockHash = RPCClient.GetBlockHash(blockIndex);
                    var blockData = RPCClient.GetBlockData(blockHash);
                    // decode the block
                    var block = new Block(ByteToHex.StringToByteArray(blockData))
                    {
                        FirstSeen = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
                    };
                    // add the block to the database
                    Database.EnqueueTask(new DatabaseWrite(block), 0);
                    // process all transactions that occured in the block
                    foreach (var transaction in block.Transactions)
                    {
                        // does this transaction contain an output we are watching?
                        SubscriptionCheck.CheckForSubscription(transaction);
                    }
                }

                stopWatch.Stop();
                var elapsed = stopWatch.Elapsed;
                Console.Write("Processed blocks in " + $"{elapsed.Hours:00}:{elapsed.Minutes:00}:{elapsed.Seconds:00}.{elapsed.Milliseconds / 10:00}");
            }
            Console.WriteLine();

            // get websocket listen address/port from app settings
            var websocketListen = ConfigurationManager.AppSettings["WebSocketListen"];

            // start websocket server
            WebSocketServer = new WebSocket.Server(websocketListen);

            // get ZMQ server address from app settings
            var zmqServerTX    = ConfigurationManager.AppSettings["ZMQPublisherRawTX"];
            var zmqServerBlock = ConfigurationManager.AppSettings["ZMQPublisherRawBlock"];

            // start ZMQ subscribers
            new ZMQ.Subscriber(zmqServerTX, "rawtx", new TXConsumer());
            new ZMQ.Subscriber(zmqServerBlock, "rawblock", new BlockConsumer());

            // skip scanning the mempool if there is no saved block data yet (TODO: maybe it should still scan?)
            if (lastBlock != null)
            {
                // fetch the mempool
                var memPool = RPCClient.GetMemPool();
                Console.WriteLine("Mempool contains " + memPool.Length + " transactions; processing...");

                // record how long it takes to process the mempool
                var stopWatch2 = new Stopwatch();
                stopWatch2.Start();
                // process all mempool transactions
                foreach (var txid in memPool)
                {
                    var rawTransaction = RPCClient.GetRawTransaction(txid);
                    var transaction    = new Transaction(rawTransaction)
                    {
                        FirstSeen   = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
                        LastUpdated = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
                    };

                    // does this transaction contain an output we are watching?
                    SubscriptionCheck.CheckForSubscription(transaction);
                }

                stopWatch2.Stop();
                var elapsed2 = stopWatch2.Elapsed;
                Console.WriteLine("Processed mempool in " +
                                  $"{elapsed2.Hours:00}:{elapsed2.Minutes:00}:{elapsed2.Seconds:00}.{elapsed2.Milliseconds / 10:00}");
            }
            else
            {
                Console.WriteLine("Skipping mempool scan on first run.");
            }
        }
예제 #9
0
 private static void Cleanup()
 {
     RPCClient.Cleanup();
 }
 private void CheckCapabilities(RPCClient rpc, string command, bool supported)
 {
     CheckCapabilities(() => rpc.SendCommand(command, "random"), supported);
 }
예제 #11
0
 public static RPCClient WithCapabilitiesOf(this RPCClient client, RPCClient target)
 {
     client.Capabilities = target.Capabilities;
     return(client);
 }
예제 #12
0
파일: Program.cs 프로젝트: gezidan/ZYSOCKET
        static void Main(string[] args)
        {


            RPCClient client = new RPCClient();
            if (client.Connection("127.0.0.1", 9952))
            {
                client.OutTime = 2000000;
                client.Disconn += Client_Disconn;
                client.RegModule(new ClientCall());

                Console.WriteLine("input userName:"******"123123"))
                {
                    Console.WriteLine("LogOn Is OK");

                    while (true)
                    {
                        string msg = Console.ReadLine();

                        client.GetRPC<ServerClass>().SendAll(msg);


                        DateTime time = client.GetRPC<ServerClass>().GetServerTime();

                        Console.WriteLine("Serve time is " + time);

                        int value = 0;

                        client.GetRPC<ServerClass>().OutRandom(out value);

                        Console.WriteLine("Random value is " + value);

                        Data x = new Data()
                        {
                            Name = "II"
                        };

                        var v = client.GetRPC<ServerClass>().Return(x);

                        Console.WriteLine("Data Name " + v.Name);

                        var l = client.GetRPC<ServerClass>().RecComputer(10); //这叫递归吗? 代价太大,深度最好别超过5层 实在没办法记得设置outtime

                        Console.WriteLine("Rec computer value:" + l);


                        var arry = client.GetRPC<ServerClass>().array(new string[] { "123", "321" }); //array


                        var arry2 = client.GetRPC<ServerClass>().array(new Data[] { new Data() { Name = "1" }, new Data() { Name = "2" } }); // class array

                        var arry3 = client.GetRPC<ServerClass>().array(new int[] { 123, 321 }); //int array

                        var arry4 = client.GetRPC<ServerClass>().array(new float[] { 123.0f, 321.0f }); //int array
                    }

                }

            }

        }