Client/Client.cs
author sl
Thu, 14 Aug 2014 18:37:23 +0200
changeset 29 c4e03315035c
parent 26 a6fb2b2f73b0
child 30 c375286d1a1c
permissions -rw-r--r--
Client/Server duplex is still a mess in C#.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 using System.Windows.Forms;
     7 using SharpDisplayInterface;
     8 using System.ServiceModel;
     9 using System.ServiceModel.Channels;
    10 
    11 
    12 namespace SharpDisplayClient
    13 {
    14     /// <summary>
    15     ///
    16     /// </summary>
    17     public partial class Callback : IDisplayServiceCallback, IDisposable
    18     {
    19         public void OnConnected()
    20         {
    21             //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
    22             //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
    23 
    24             MessageBox.Show("OnConnected()", "Client");
    25         }
    26 
    27 
    28         public void OnServerClosing()
    29         {
    30             //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
    31             //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
    32 
    33             //MessageBox.Show("OnServerClosing()", "Client");
    34             Program.iMainForm.CloseConnection();
    35             Program.iMainForm.Close();
    36         }
    37 
    38         //From IDisposable
    39         public void Dispose()
    40         {
    41 
    42         }
    43     }
    44 
    45 
    46     /// <summary>
    47     ///
    48     /// </summary>
    49     public partial class Client : DuplexClientBase<IDisplayService>
    50     {
    51         private string Name { get; set; }
    52 
    53         public Client(InstanceContext callbackInstance)
    54             : base(callbackInstance, new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:8001/DisplayService"))
    55         { }
    56 
    57         public void Connect(string aClientName)
    58         {
    59             Name = aClientName;
    60             Channel.Connect(aClientName);
    61         }
    62 
    63         public void Disconnect()
    64         {
    65             Channel.Disconnect(Name);
    66             Name = "";
    67         }
    68 
    69         public void SetText(int aLineIndex, string aText)
    70         {
    71             Channel.SetText(aLineIndex, aText);
    72         }
    73 
    74 
    75         public void SetTexts(System.Collections.Generic.IList<string> aTexts)
    76         {
    77             Channel.SetTexts(aTexts);
    78         }
    79 
    80     }
    81 }