"Fossies" - the Fresh Open Source Software Archive

Member "muscle/csharp/test/ExampleClient.cs" (8 Jun 2019, 1938 Bytes) of package /linux/privat/muscle7.30.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 namespace muscle.test {
    2   using System;
    3   using System.IO;
    4   using System.Net;
    5   using System.Net.Sockets;
    6   using System.Text;
    7   using System.Collections;
    8   using System.Diagnostics;
    9   using System.Threading;
   10 
   11   using muscle.message;
   12   using muscle.client;
   13   using muscle.iogateway;
   14 
   15   public class ExampleClient {
   16     static void Main() {
   17       string [] args = Environment.GetCommandLineArgs();
   18 
   19       string host = "127.0.0.1";
   20       int port = 2960;
   21 
   22       if (args.Length >= 2)
   23     host = args[1];
   24 
   25       if (args.Length >= 3)
   26     port = System.Int32.Parse(args[2]);
   27 
   28       new ExampleClient(host, port); 
   29     }
   30       
   31     public ExampleClient(string hostName, int port)
   32     {
   33       Client client = new Client(hostName, port);
   34 
   35       client.RegisterForMessages(new MessagesCallback(MessagesCallback), null);
   36       client.RegisterForDisconnect(new DisconnectCallback(DisconnectCallback),
   37                    null);
   38 
   39       client.BeginConnect(new AsyncCallback(this.ConnectCallback), client);
   40 
   41       Message m1 = new Message();
   42 
   43       m1.what = StorageReflectConstants.PR_COMMAND_SETPARAMETERS;
   44       m1.setBoolean("SUBSCRIBE:*", true);
   45       m1.setBoolean("SUBSCRIBE:*/*", true);
   46       m1.setBoolean("SUBSCRIBE:*/*/*", true);
   47       m1.setBoolean("SUBSCRIBE:*/*/*/*", true);
   48       m1.setBoolean("SUBSCRIBE:*/*/*/*/*", true);
   49 
   50       client.Send(m1);
   51 
   52       while (true) {
   53     Thread.Sleep(5000);
   54       }
   55     }
   56 
   57     public void ConnectCallback(IAsyncResult ar) 
   58     {
   59       Client client = (Client) ar.AsyncState;
   60       client.EndConnect(ar);
   61     }
   62 
   63     public void DisconnectCallback(Client client,
   64                    Exception err,
   65                    object state)
   66     {
   67       Console.WriteLine(err.ToString());
   68       Console.WriteLine("disconnected");
   69 
   70     }
   71 
   72     public void MessagesCallback(Message [] messages,
   73                  Client client, 
   74                  object state) 
   75     {
   76       foreach (Message message in messages) {
   77     System.Console.WriteLine(message.ToString());
   78       }
   79     }
   80     
   81   }
   82 }