コード例 #1
0
    static CMyStruct Load(CUQueue q)
    {
        CMyStruct ms = new CMyStruct();

        ms.LoadFrom(q);
        return(ms);
    }
コード例 #2
0
    static void Main(string[] args)
    {
        CClientSocket.QueueConfigure.MessageQueuePassword = "******";
        SetWorkDirectory();
        ReplicationSetting rs = new ReplicationSetting();

        using (CReplication <HelloWorld> hw = new CReplication <HelloWorld>(rs))
        {
            Dictionary <string, CConnectionContext> ConnQueue = new Dictionary <string, CConnectionContext>();
            CConnectionContext cc = new CConnectionContext("127.0.0.1", 20901, "replication", "p4localhost");
#if PocketPC
#else
            ConnQueue["Tolocal"] = cc;
#endif
            cc = new CConnectionContext("192.168.1.109", 20901, "remote_rep", "PassOne");
            ConnQueue["ToLinux"] = cc;
            bool ok = hw.Start(ConnQueue, "hw_root_queue_name");
            hw.StartJob();
            ok = hw.Send(hwConst.idSayHelloHelloWorld, "David", "Young");
            ok = hw.Send(hwConst.idEchoHelloWorld, CMyStruct.MakeOne());
            hw.EndJob();
            Console.WriteLine("Press key ENTER to shut down the application ......");
            Console.ReadLine();
        }
    }
コード例 #3
0
    public CMyStruct Echo(CMyStruct ms)
    {
        CMyStruct EchoRtn;
        bool      bProcessRy = ProcessR1(hwConst.idEchoHelloWorld, ms, out EchoRtn);

        return(EchoRtn);
    }
コード例 #4
0
ファイル: Program.cs プロジェクト: udaparts/socketpro
    static void Main(string[] args)
    {
        using (CScopeUQueue sb = new CScopeUQueue())
        {
            CMyStruct msOrig = CMyStruct.MakeOne();
            sb.Save(msOrig);
            CMyStruct ms = sb.Load <CMyStruct>();
            System.Diagnostics.Debug.Assert(sb.UQueue.GetSize() == 0);

            //check if both msOriginal and ms are equal in value.
        }
    }
コード例 #5
0
    static void Main(string[] args)
    {
        using (CScopeUQueue su = new CScopeUQueue())
        {
            CMyStruct msOriginal = CMyStruct.MakeOne();

            msOriginal.SaveTo(su.UQueue);

            CMyStruct ms = Load(su.UQueue);
            System.Diagnostics.Debug.Assert(su.UQueue.GetSize() == 0);

            //check if both msOriginal and ms are equal in value.
        }
    }
コード例 #6
0
ファイル: mystruct.cs プロジェクト: udaparts/socketpro
 public static CMyStruct MakeOne()
 {
     CMyStruct msOriginal = new CMyStruct();
     int[] arrInt = { 1, 76890 };
     msOriginal.objArrInt = arrInt;
     string[] arrString = { "Hello", "world" };
     msOriginal.objArrString = arrString;
     msOriginal.ObjBool = true;
     msOriginal.ObjString = "test";
     msOriginal.UnicodeString = "Unicode";
     msOriginal.ABool = true;
     msOriginal.ADouble = 1234.567;
     msOriginal.AsciiString = System.Text.ASCIIEncoding.ASCII.GetBytes("ASCII");
     return msOriginal;
 }
コード例 #7
0
    public static CMyStruct MakeOne()
    {
        CMyStruct msOriginal = new CMyStruct();

        int[] arrInt = { 1, 76890 };
        msOriginal.objArrInt = arrInt;
        string[] arrString = { "Hello", "world" };
        msOriginal.objArrString  = arrString;
        msOriginal.ObjBool       = true;
        msOriginal.ObjString     = "test";
        msOriginal.UnicodeString = "Unicode";
        msOriginal.ABool         = true;
        msOriginal.ADouble       = 1234.567;
        msOriginal.AsciiString   = System.Text.ASCIIEncoding.ASCII.GetBytes("ASCII");
        return(msOriginal);
    }
コード例 #8
0
ファイル: Program.cs プロジェクト: warrior6/socketpro
    static void Main(string[] args)
    {
        CConnectionContext cc = new CConnectionContext("localhost", 20901, "hwClientUserId", "password4hwClient");

        using (CSocketPool <HelloWorld> spHw = new CSocketPool <HelloWorld>(true)) //true -- automatic reconnecting
        {
            bool       ok = spHw.StartSocketPool(cc, 1, 1);
            HelloWorld hw = spHw.Seek(); //or HelloWorld hw = spHw.Lock();

            //optionally start a persistent queue at client side to ensure auto failure recovery and once-only delivery
            ok = hw.AttachedClientSocket.ClientQueue.StartQueue("helloworld", 24 * 3600, false); //time-to-live 1 day and true for encryption

            //process requests one by one synchronously
            Console.WriteLine(hw.SayHello("Jone", "Dole"));
            hw.Sleep(5000);
            CMyStruct msOriginal = CMyStruct.MakeOne();
            CMyStruct ms         = hw.Echo(msOriginal);

            //asynchronously process multiple requests with inline batching for best network efficiency
            ok = hw.SendRequest(hwConst.idSayHelloHelloWorld, "Jack", "Smith", (ar) =>
            {
                string ret;
                ar.Load(out ret);
                Console.WriteLine(ret);
            });
            CAsyncServiceHandler.DAsyncResultHandler arh = null;
            ok = hw.SendRequest(hwConst.idSleepHelloWorld, (int)5000, arh);
            ok = hw.SendRequest(hwConst.idEchoHelloWorld, msOriginal, (ar) =>
            {
                ar.Load(out ms);
            });
            ok = hw.WaitAll();
            Console.WriteLine("Press ENTER key to shutdown the demo application ......");
            Console.ReadLine();
        }
    }
コード例 #9
0
ファイル: hwImpl.cs プロジェクト: udaparts/socketpro
 private CMyStruct Echo(CMyStruct ms)
 {
     return ms;
 }
コード例 #10
0
ファイル: hwImpl.cs プロジェクト: udaparts/socketpro
 private CMyStruct Echo(CMyStruct ms)
 {
     return(ms);
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: udaparts/socketpro
    static void Main(string[] args)
    {
        CConnectionContext cc = new CConnectionContext("localhost", 20901, "hwClientUserId", "password4hwClient");

        using (CSocketPool <HelloWorld> spHw = new CSocketPool <HelloWorld>())
        {
            //optionally start a persistent queue at client side to
            //ensure auto failure recovery and once-only delivery
            //spHw.QueueName = "helloworld";
            CMyStruct ms, msOrig = CMyStruct.MakeOne();
            if (spHw.StartSocketPool(cc, 1))
            {
                HelloWorld hw = spHw.Seek();
                try
                {
                    //process requests one by one synchronously
                    Task t0 = hw.sendRequest(hwConst.idSayHelloHelloWorld, "John", "Dole");
                    Console.WriteLine(t0.Result.Load <string>());
                    Task t1 = hw.sendRequest(hwConst.idSleepHelloWorld, (int)4000);
                    Console.WriteLine("Returned buffer size should be " + t1.Result.UQueue.Size + " because server returns nothing");
                    Task t2 = hw.sendRequest(hwConst.idEchoHelloWorld, msOrig);
                    ms = t2.Result.Load <CMyStruct>();

                    //All requests are streamed with in-line batch for the best network efficiency
                    t0 = hw.sendRequest(hwConst.idSayHelloHelloWorld, "John", "Dole");
                    t1 = hw.sendRequest(hwConst.idSleepHelloWorld, (int)4000);
                    t2 = hw.sendRequest(hwConst.idEchoHelloWorld, msOrig);
                    Task t3 = hw.sendRequest(hwConst.idSayHelloHelloWorld, "Jack", "Smith");
                    Task t4 = hw.sendRequest(hwConst.idSayHelloHelloWorld, "Donald", "Trump");
                    Task t5 = hw.sendRequest(hwConst.idSleepHelloWorld, (int)15000);
                    Task t6 = hw.sendRequest(hwConst.idSayHelloHelloWorld, "Hillary", "Clinton");
                    Task t7 = hw.sendRequest(hwConst.idEchoHelloWorld, msOrig);
                    //hw.Socket.Cancel();
                    Console.WriteLine(t0.Result.Load <string>());
                    Console.WriteLine("Returned buffer size should be " + t1.Result.UQueue.Size + " because server returns nothing");
                    ms = t2.Result.Load <CMyStruct>();
                    Console.WriteLine(t3.Result.Load <string>());
                    Console.WriteLine(t4.Result.Load <string>());
                    Console.WriteLine("Returned buffer size should be " + t5.Result.UQueue.Size + " because server returns nothing");
                    Console.WriteLine(t6.Result.Load <string>());
                    ms = t7.Result.Load <CMyStruct>();
                }
                catch (AggregateException ex)
                {
                    foreach (Exception e in ex.InnerExceptions)
                    {
                        //An exception from server (CServerError), Socket closed
                        //after sending a request (CSocketError) or canceled (CSocketError),
                        Console.WriteLine(e);
                    }
                }
                catch (CSocketError ex)
                {
                    //Socket is already closed before sending a request
                    Console.WriteLine(ex);
                }
                catch (Exception ex)
                {
                    //bad operations such as invalid arguments,
                    //bad operations and de-serialization errors, and so on
                    Console.WriteLine(ex);
                }
            }
            else
            {
                Console.WriteLine("No connection to server with error message: " + spHw.Sockets[0].ErrorMsg);
            }
            Console.WriteLine("Press ENTER key to kill the demo ......");
            Console.ReadLine();
        }
    }
コード例 #12
0
 static void Save(CMyStruct ms, CUQueue q)
 {
     ms.SaveTo(q);
 }
コード例 #13
0
ファイル: hw.cs プロジェクト: udaparts/socketpro
 public CMyStruct Echo(CMyStruct ms)
 {
     CMyStruct EchoRtn;
     bool bProcessRy = ProcessR1(hwConst.idEchoHelloWorld, ms, out EchoRtn);
     return EchoRtn;
 }