API version 1

- ‐

stop

ソケットの受信待機を停止します。

SocketListenerオブジェクトの消滅時にもイベントの待ち受けを停止しますが、CRSではオブジェクトの消滅タイミングは不定です。 必ずstopメソッドを呼び出して停止させてください。

呼出形式一覧

呼出形式

説明

void stop()

受信待機を停止します。

戻り値一覧

戻り値

説明

void

なし

例外

なし

関連項目

isListening プロパティ

start メソッド



使用例 CRSダウンロード ダウンロード(TcpSocketC.crs)

Form TcpSocketListener {
   X = 0;
   Y = 0;
   Width = 733;
   Height = 569;
   BgColor = new Color(204,204,255,255);

/*
  このサンプルは TcpSocketC とセットで使います
  初めに TcpSocketListenerS を起動して start します
  次に TcpSocketC を起動して 接続(open) します
  ポートは netstat 等で使用可能なポートを選んでください
*/

   number size=0;
   string sname;

   Label Label1 {
           X = 23;
           Y = 27;
           Width = 122;
           Height = 21;
           Value = "TCPサーバーソケット";
           var fon = new Font("", "", true);
           Font = fon;
           FgColor = Color.Blue;
   }
   TextBox txtSocketName {
           X = 148;
           Y = 26;
           Width = 175;
           Height = 27;
   }

   TcpSocketListener sock_listener {

           Function OnAccept(e) {
                   var obj = e.Socket;
                   ^.txtSocketName.Value = obj.name;
                   TcpSocketListener.sname = obj.name;
                   ^.lblReceive = "接続 オブジェクト名=" + obj.name +
                           " ホスト=" + obj.host + " ポート=" + str(obj.port) ;
           }

           Function OnReceive(e) {

                   /* if (e.from.name == socketName) { */
                   var obj = e.from;

                   if (e.from.name == obj.name) {
                           var data;

                           data = obj.Read(256);
                           var data2 = data.toString();
                           ^.txtString2.Value = data2;
                           ^.lblRSize[0] = data2.length;
                   }
           }
   }

   Label lblReceive {
           X = 23;
           Y = 58;
           Width = 684;
           Height = 24;
   }

   Label Label2 {
           X = 24;
           Y = 90;
           Width = 42;
           Height = 19;
           Value = "Port";
   }
   TextBox txtPort {
           X = 67;
           Y = 88;
           Width = 70;
           Height = 23;
           Value = 8887;
   }
   Label lblPort2 {
           X = 138;
           Y = 88;
           Width = 70;
           Height = 23;
           Value = "";

           Function OnClicked( e ) {
                   this.Clear();
           }
   }
   Button btnStart {
           X = 214;
           Y = 86;
           Width = 98;
           Height = 27;
           Title = "Start";

           Function OnTouch( e ) {
                   try {
                           if (^.sock_listener.Start(^.txtPort)) {
                                   ^.lblPort2 = ^.sock_listener.port;
                                   ^.btnIsLis.PostEvent(new Event("TOUCH"));
                           } else {
                                   //.MessageBox("startできませんでした");
                           }

                   } catch(e) {
                           ^.sock_listener.Stop();
                           ^.lblReceive.Clear();
                           MessageBox("Message=" + str(e.Message) + "\nCategory=" + str(e.Category) + "\nCode="+ str(e.Code)  + "\nSubCode=" + str(e.subCode));
                   }
           }
   }
   Button btnStop {
           X = 314;
           Y = 86;
           Width = 98;
           Height = 27;
           Title = "Stop";

           Function OnTouch( e ) {
                   try {
                           ^.sock_listener.Stop();
                           ^.lblReceive.Clear();
                           ^.btnIsLis.PostEvent(new Event("TOUCH"));
                   } catch(e) {
                           MessageBox("Message=" + str(e.Message) + "\nCategory=" + str(e.Category) + "\nCode="+ str(e.Code)  + "\nSubCode=" + str(e.subCode));
                   }
           }
   }
   Label lblIsLis {
           X = 529;
           Y = 87;
           Width = 69;
           Height = 26;
           Function OnClicked( e ) {
                   this.Clear();
           }
   }

   Button btnIsLis {
           X = 419;
           Y = 86;
           Width = 105;
           Height = 27;
           Title = "IsListening";
           Function OnTouch( e ) {
                   try {
                           ^.lblIsLis.Value = ^.sock_listener.IsListening ? "待受け中" : "停止中";
                   }
                   catch(e) {
                           MessageBox("Message=" + str(e.Message) + "\nCategory=" + str(e.Category) + "\nCode="+ str(e.Code)  + "\nSubCode=" + str(e.subCode));
                   }
           }
   }

   Label Label4 {
           X = 30;
           Y = 170;
           Width = 78;
           Height = 18;
           Value = "EditBox1";
           TabIndex = 2;
   }
   EditBox EdiString {
           X = 30;
           Y = 190;
           Width = 163;
           Height = 70;
           TabIndex = 2;
   }
   Button btnWrite {
           X = 199;
           Y = 188;
           Width = 117;
           Height = 29;
           Title = "送信(Write)";
           TabIndex = 2;

           Function OnTouch( e ) {
                   try {
                           var sock = ^.sock_listener.FindObject(TcpSocketListener.sname);

                           if (sock != null) {
                                   sock.Write(^.EdiString.Value);
                           }
                   }
                   catch(e) {
                           MessageBox("Message=" + str(e.Message) + "\nCategory=" + str(e.Category) + "\nCode="+ str(e.Code)  + "\nSubCode=" + str(e.subCode));
                   }
           }
   }


   Label Label9 {
           X = 459;
           Y = 168;
           Width = 74;
           Height = 20;
           Value = "受信データ";
           TabIndex = 2;
   }
   TextBox txtString2 {
           X = 458;
           Y = 189;
           Width = 163;
           Height = 26;
           TabIndex = 2;
   }
   Button btnClear {
           X = 586;
           Y = 169;
           Width = 34;
           Height = 19;
           Title = "C";
           TabIndex = 2;
           Function OnTouch( e ) {
                   ^.txtString2.Clear();
                   ^.lblRSize[0].clear();
           }
   }

   Label Label10 {
           X = 626;
           Y = 167;
           Width = 72;
           Height = 21;
           Value = "受信サイズ";
           TabIndex = 2;
   }
   Label lblRSize[1] {
           X = 626;
           Y = 191;
           Width = 72;
           Height = 23;
           Layout = LAYOUT_BLANK;
           this[0].y = 191;
           TabIndex = 2;

           Function OnClicked( e ) {
                   this.Clear();
           }
   }
}