package Microsoft.Samples;
//-----------------------------------------------------------------------
//  This file is part of the Microsoft .NET Framework SDK Code Samples.
// 
//  Copyright (C) Microsoft Corporation.  All rights reserved.
// 
// This source code is intended only as a supplement to Microsoft
// Development Tools and/or on-line documentation.  See these other
// materials for detailed information regarding Microsoft code samples.
// 
// THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//-----------------------------------------------------------------------
import System.*;
import System.Threading.*;
import System.Runtime.Remoting.*;
import System.Runtime.Remoting.Channels.*;
import System.Runtime.Remoting.Channels.Http.*;
import System.Runtime.Remoting.Channels.Tcp.*;

public class Client
{
    public boolean init = false;
    public static System.Threading.Thread thread1 = null;
    public static System.Threading.Thread thread2 = null;

    public static void main(String[] args)
    {
        Client c = new Client();
        thread1 = new System.Threading.Thread(new ThreadStart(c.RunMe));
        thread2 = new System.Threading.Thread(new ThreadStart(c.RunMe));
        thread1.Start();
        thread2.Start();
    } //main

    public void RunMe()
    {
        if (System.Threading.Thread.get_CurrentThread().Equals(thread1)) {
            HttpChannel chan = new HttpChannel();
            ChannelServices.RegisterChannel(chan, false);
            Console.WriteLine("I am thread one");
            HelloServer obj = (HelloServer)(Activator.GetObject(HelloServer.
                class.ToType(), "http://localhost:8086/SayHello"));

            for (int i = 0; i < 1000; i++) {
                Console.WriteLine(obj.CountMe() + " - from thread 1 ");
                System.Threading.Thread.Sleep(0);
            }
        }
        else {
            if (System.Threading.Thread.get_CurrentThread().Equals(thread2)) {
                TcpChannel chan = new TcpChannel();
                ChannelServices.RegisterChannel(chan, true);
                Console.WriteLine("I am thread two");
                HelloServer obj = (HelloServer)(Activator.GetObject(HelloServer.
                    class.ToType(), "tcp://localhost:8085/SayHello"));

                for (int i = 0; i < 1000; i++) {
                    Console.WriteLine(obj.CountMe() + " - from thread 2 ");
                    System.Threading.Thread.Sleep(0);
                }
            }
        }
    } //RunMe
} //Client