Beispiel #1
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="localPort">自分のポート</param>
        public RemoteHost(int localPort, DebugWindow debugwindow, TerminalConnection.TerminalConnection TC)
        {
            try
            {
                this.UP_Cliant  = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(localPort);
                this.UP_Encoder = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
                this.UP_Decoder = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                this.id         = localPort;

                this.CTS    = new CancellationTokenSource();
                this.mytask = new Task(() => this.Main_Task(), CTS.Token);

                this.mytask.Start();
                this.fpsa = new FPSAdjuster.FPSAdjuster();

                this.debugwindow          = debugwindow;
                this.debugwindow.DebugLog = "[Port:" + localPort.ToString() + "]受信を開始します";

                this.TC = TC;
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="localPort">自分のポート</param>
        public RemoteHost(int localPort, DebugWindow debugwindow/*, TerminalConnection.TerminalConnection TC*/)
        {
            try
            {
                this.UP_Cliant = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(localPort);
                this.UP_Encoder = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
                this.UP_Decoder = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                this.id = localPort;

                this.CTS = new CancellationTokenSource();
                this.mytask = new Task(() => this.Main_Task(), CTS.Token);

                this.mytask.Start();
                this.fpsa = new FPSAdjuster.FPSAdjuster();

                this.debugwindow = debugwindow;
                this.debugwindow.DebugLog = "[Port:" + localPort.ToString() + "]受信を開始します";

                //this.TC = TC;
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 接続を切断します。
        /// </summary>
        public void disconnect()
        {
            try
            {
                this.debugwindow.DebugLog = "[Port:" + this.ID.ToString() + "]切断します.";
                UP_Cliant.Close();
                this.data = null;
                if (this.connect_host != null)
                {
                    this.connect_host.connect_host = null;
                    this.connect_host = null;
                }

                CTS.Cancel();
                isConnected     = false;
                this.UP_Encoder = null;
                this.UP_Decoder = null;

                this.UP_Cliant = null;

                this.DataReceived = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "接続の切断に失敗しました。");
            }
            finally
            {
            }
        }
Beispiel #4
0
 public void Close()
 {
     this.udp_client.Close();
     this.udp_client = null;
     Thread.Sleep(100);
     this.Close_add();
 }
Beispiel #5
0
        private void Connect()
        {
            this.Connect_add();
            switch (this.mode)
            {
            case MODE.non:
                this.mode = SETTINGS.MyInfo.Mode;
                Connect();
                break;

            case MODE.Sender:
                this.udp_client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(this.serverIP, this.remotePort, this.myPort);
                Connect_Sender_add();
                break;

            case MODE.Receiver:
                this.udp_client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(this.serverIP, this.remotePort, this.myPort);
                Connect_Receiver_add();
                break;

            case MODE.Both:
                this.udp_client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(this.serverIP, this.remotePort, this.myPort);
                Connect_Both_add();
                break;

            case MODE.DirectConnect:
                this.udp_client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(this.serverIP, this.remotePort, this.myPort);
                Connect_Direct_add();
                break;

            default:
                break;
            }
        }
Beispiel #6
0
 public void Close()
 {
     this.udp_client.Close();
     this.udp_client = null;
     Thread.Sleep(100);
     this.Close_add();
 }
Beispiel #7
0
        public ClientHost(int Port)
        {
            this.clientstatus            = new ClientStatus();
            this.clientstatus.ServerPort = Port;

            this.client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(Port);
            this.client.DataReceived += client_DataReceived_Init;
        }
Beispiel #8
0
        public RemoteHostServer()
        {
            try
            {
                client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(myPort);
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }

            try
            {
                this.enc     = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
                this.dec     = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                this.LstPort = new List <int>();

                mytask = new Task(() => this.MAIN_TASK());
                mytask.Start();
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
            try
            {
                #region create remotehost servers list and one remotehost server
                this.List_remotehost = new List <RemoteHost>();
                #endregion
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// サーバがアクセスされるまで待機し、アクセスされた場合そのメッセージを検査し、その情報に従って
        /// ポートを割り振る、もしくは終了します。
        /// </summary>
        /// <returns></returns>
        private void update(ref int Port, ref bool isConnect)
        {
            try
            {
                this.client.Close();
                this.client = null;
                Thread.Sleep(100);
                this.client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(myPort);
                this.debugwindow.DebugLog = "[RemoteHostServer]操作受付を開始します.ポート:" + this.server_port;
                while (true)
                {
                    if (this.client.Received_Data != null)
                    {
                        dec.Source = this.client.Received_Data;
                        break;
                    }
                    Thread.Sleep(10);
                }

                Thread.Sleep(100);
                switch (dec.get_int())
                {
                case Definitions.CONNECTION_DEMANDS:
                    isConnect = true;
                    break;

                case Definitions.CONNECTION_END:
                    isConnect = false;
                    break;

                default:
                    this.debugwindow.DebugLog = "要求された信号に対応するコマンドが存在しません。リモートホスト側のコネクトの設定を確認してください。";
                    break;
                }

                if (isConnect)
                {
                    this.connect(ref Port);
                }
                else
                {
                    this.disconnect(dec.get_int());
                    try
                    {
                        this.terminalconnection.Tcp_Send();
                    }
                    catch (Exception ex)
                    {
                        debugwindow.DebugLog = "[" + this.ToString() + "]" + ex.Message;
                    }
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "ポートを割り振るサーバのアップデートでエラーが発生しました。");
            }
        }
Beispiel #10
0
 public void Close()
 {
     if (IsClosed == false)
     {
         this.udp_client.Close();
         this.udp_client = null;
         Thread.Sleep(100);
         this.Close_add();
         this.IsClosed = true;
     }
 }
Beispiel #11
0
        public static void DisconnectByUserPort(int SenderUserPort, int ReceiverUserPort, string RemoteIP, int RemotePort, int myPort)
        {
            UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(RemoteIP, RemotePort, myPort);
            UDP_PACKETS_CODER.UDP_PACKETS_ENCODER enc    = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
            enc += (int)14;
            enc += SenderUserPort;
            enc += ReceiverUserPort;

            client.Send(enc.data);
            client.Close();
        }
Beispiel #12
0
        public static void Connect(int SenderID, int ReceiverID, string RemoteIP, int RemotePort, int myPort)
        {
            UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(RemoteIP, RemotePort, myPort);
            UDP_PACKETS_CODER.UDP_PACKETS_ENCODER enc    = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
            enc += (int)5;
            enc += SenderID;
            enc += ReceiverID;

            client.Send(enc.data);
            client.Close();
        }
Beispiel #13
0
        public static void Disconnect(int SenderID, int ReceiverID, string RemoteIP, int RemotePort, int myPort)
        {
            UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(RemoteIP, RemotePort, myPort);
            UDP_PACKETS_CODER.UDP_PACKETS_ENCODER enc = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
            enc += (int)6;
            enc += SenderID;
            enc += ReceiverID;

            client.Send(enc.data);
            client.Close();
        }
Beispiel #14
0
        public static void ConnectByUserPort(int SenderUserPort, int ReceiverUserPort, string RemoteIP, int RemotePort, int myPort)
        {
            UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(RemoteIP, RemotePort, myPort);
            UDP_PACKETS_CODER.UDP_PACKETS_ENCODER enc = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
            enc += (int)13;
            enc += SenderUserPort;
            enc += ReceiverUserPort;

            client.Send(enc.data);
            client.Close();
        }
Beispiel #15
0
 public void Close()
 {
     if (IsClosed == false)
     {
         this.udp_client.Close();
         this.udp_client = null;
         Thread.Sleep(100);
         this.Close_add();
         this.IsClosed = true;
     }
 }
Beispiel #16
0
        public void Close()
        {
            foreach (var p in this.List_ClientHosts)
            {
                p.Close();
            }

            this.client.DataReceived -= client_DataReceived;
            this.client.Close();
            this.client = null;
        }
Beispiel #17
0
        public MainServer()
        {
            this.Init_Classes();

            this.Load_Settings();

            this.CurrentPort = int.Parse(this.settings.StartPort);
            this.StartPort = this.CurrentPort;

            this.client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(int.Parse(this.settings.PortNum));
            this.client.DataReceived += client_DataReceived;
        }
Beispiel #18
0
        public MainServer()
        {
            this.Init_Classes();

            this.Load_Settings();

            this.CurrentPort = int.Parse(this.settings.StartPort);
            this.StartPort   = this.CurrentPort;

            this.client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(int.Parse(this.settings.PortNum));
            this.client.DataReceived += client_DataReceived;
        }
Beispiel #19
0
 public void Setup(MODE mode)
 {
     this.udp_client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(this.remoteIP, this.serverPort, this.myPort);
     this.mode = mode;
     this.Connect();
 }
Beispiel #20
0
 private void Connect()
 {
     this.Connect_add();
     switch (this.mode)
     {
         case MODE.non:
             this.mode = SETTINGS.MyInfo.Mode;
             Connect();
             break;
         case MODE.Sender:
             this.udp_client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(this.remoteIP, this.remotePort, this.myPort);
             Connect_Sender_add();
             break;
         case MODE.Receiver:
             this.udp_client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(this.remoteIP, this.remotePort, this.myPort);
             Connect_Receiver_add();
             break;
         default:
             break;
     }
 }
        public RemoteHostServer()
        {
            try
            {
                client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(myPort);
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }

            try
            {
                this.enc = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
                this.dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                this.LstPort = new List<int>();

                mytask = new Task(() => this.MAIN_TASK());
                mytask.Start();
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
            try
            {
                #region create remotehost servers list and one remotehost server
                this.List_remotehost = new List<RemoteHost>();
                #endregion
            }
            catch(Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// サーバがアクセスされるまで待機し、アクセスされた場合そのメッセージを検査し、その情報に従って
        /// ポートを割り振る、もしくは終了します。
        /// </summary>
        /// <returns></returns>
        private void update(ref int Port, ref bool isConnect)
        {
            try
            {
                this.client.Close();
                this.client = null;
                Thread.Sleep(100);
                this.client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(myPort);
                this.debugwindow.DebugLog = "[RemoteHostServer]操作受付を開始します.ポート:" + this.server_port;
                while (true)
                {
                    if (this.client.Received_Data != null)
                    {
                        dec.Source = this.client.Received_Data;
                        break;
                    }
                    Thread.Sleep(10);
                }

                Thread.Sleep(100);
                switch (dec.get_int())
                {
                    case Definitions.CONNECTION_DEMANDS:
                        isConnect = true;
                        break;
                    case Definitions.CONNECTION_END:
                        isConnect = false;
                        break;
                    default:
                        this.debugwindow.DebugLog = "要求された信号に対応するコマンドが存在しません。リモートホスト側のコネクトの設定を確認してください。";
                        break;
                }

                if (isConnect)
                {
                    this.connect(ref Port);
                }
                else
                {
                    this.disconnect(dec.get_int());
                    try
                    {
                        this.terminalconnection.Tcp_Send();
                    }
                    catch (Exception ex)
                    {
                        debugwindow.DebugLog = "[" + this.ToString() + "]" + ex.Message;
                    }
                }

            }catch(Exception ex)
            {
                MessageBox.Show( ex.Message + "ポートを割り振るサーバのアップデートでエラーが発生しました。");
            }
        }
Beispiel #23
0
        public void Close()
        {
            foreach (var p in this.List_ClientHosts)
            {
                p.Close();
            }

            this.client.DataReceived -= client_DataReceived;
            this.client.Close();
            this.client = null;
        }
Beispiel #24
0
 public void Setup(MODE mode)
 {
     this.udp_client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(this.serverIP, this.serverPort, this.myPort);
     this.mode       = mode;
     this.Connect();
 }
Beispiel #25
0
        /// <summary>
        /// 接続を切断します。
        /// </summary>
        public void disconnect()
        {
            try
            {
                this.debugwindow.DebugLog = "[Port:" + this.ID.ToString() + "]切断します.";
                UP_Cliant.Close();
                this.data = null;
                if (this.connect_host != null)
                {
                    this.connect_host.connect_host = null;
                    this.connect_host = null;
                }

                CTS.Cancel();
                isConnected = false;
                this.UP_Encoder = null;
                this.UP_Decoder = null;

                this.UP_Cliant = null;

                this.DataReceived = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "接続の切断に失敗しました。");
            }
            finally
            {
            }
        }
        public RemoteHostServer()
        {
            try
            {
                this.Eventer = new TerminalConnectionSettings.CommandEventer();
                client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(myPort);
                this.remoteOperator = new RemoteOperater(client);
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }

            try
            {
                this.enc = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
                this.dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                this.LstPort = new List<int>();

            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
            try
            {
                #region create remotehost servers list and one remotehost server
                this.List_remotehost = new List<RemoteHost>();
                #endregion
                client.DataReceived += client_DataReceived;
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
        }
Beispiel #27
0
 public static void Connect(int SenderID, int ReceiverID, string RemoteIP, int RemotePort, int myPort)
 {
     UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(RemoteIP, RemotePort, myPort);
     Udp_Send(client, new TerminalConnectionSettings.TerminalProtocols.Connect(SenderID, ReceiverID));
     client.Close();
 }
Beispiel #28
0
 public static void DisconnectByClientName(string SenderClientName, string ReceiverClientName, string RemoteIP, int RemotePort, int myPort)
 {
     UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(RemoteIP, RemotePort, myPort);
     Udp_Send(client, new TerminalConnectionSettings.TerminalProtocols.DisConnectByName(SenderClientName, ReceiverClientName));
     client.Close();
 }
        public void SetupUDP()
        {
            try
            {
                if (!this.IsConnectionSetupped)
                {
                    var remoteport = this.window.connectionsetting.IsConnectionLocal ? this.window.connectionsetting.localport : this.window.connectionsetting.remoteport;
                    var remoteip = this.window.connectionsetting.IsConnectionLocal ? "127.0.0.1" : this.window.connectionsetting.remoteIP;
                    this.client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(remoteip, int.Parse(remoteport), 18000);
                    this.client.DataReceived += client_DataReceived;
                    //ちょっとやそっとのエラーでもがんがん復活するスタイル
                    this.client.IsRecast = true;

                    this.IsConnectionSetupped = true;
                    this.Udp_Send(new TerminalConnectionSettings.TerminalProtocols.DemmandInfo());
                    this.ConfirmCIPCServer();
                }
            }
            catch
            {
                throw;
            }
        }
Beispiel #30
0
 public static void TurnOnSyncConnect(string RemoteIP, int RemotePort, int myPort)
 {
     UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(RemoteIP, RemotePort, myPort);
     Udp_Send(client, new TerminalConnectionSettings.TerminalProtocols.TurnOnSyncConnect());
     client.Close();
 }