API version 1

- ‐

RW

number

writeTimeout

書き込み(送信)のタイムアウト値を秒で指定します。

初期値は0(無制限待機)です。

関連項目

readTimeout プロパティ



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

Form TcpSocketC {
   X = 0;
   Y = 0;
   Width = 727;
   Height = 610;
   BgColor = new Color(255,204,255,255);

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

   number size=0;

   Label Label1 {
           X = 16;
           Y = 8;
           Width = 141;
           Height = 21;
           Value = "TCPクライアントソケット";
           var fon = new Font("", "", true);
           Font = fon;
   }

   TcpSocket sock_client {
           Function OnReceive(e) {
                   var size=0;
                   var i=0;
                   /*  # ReadLine はこちらで試す
                   while (true) {
                           i++;
                           var line = ^.sock_client.ReadLine();
                           if (line.length == 0) break;
                           ^.EdiString2.Value += str(i) + ":" + line;
                           size += line.length;
                   }  */
                   ^.EdiString2.Value = ^.sock_client.Read(256) ;
           }
   }

   Label Label2 {
           X = 16;
           Y = 38;
           Width = 57;
           Height = 19;
           Value = "接続先";
   }
   TextBox txtHost {
           X = 76;
           Y = 35;
           Width = 360;
           Height = 23;
           Value = "localhost";
   }
   Label Label3 {
           X = 442;
           Y = 38;
           Width = 51;
           Height = 19;
           Value = "Port";
   }
   TextBox txtPort {
           X = 496;
           Y = 35;
           Width = 70;
           Height = 23;
           Value = 8887;
   }

   Button btnOpen {
           X = 222;
           Y = 62;
           Width = 112;
           Height = 25;
           Title = "接続(Open)";

           Function OnTouch( e ) {
                   try {
                           if (^.sock_client.Open(^.txtHost, ^.txtPort, 20)) {
                                   ^.txtPort2 = ^.sock_client.port;
                                   ^.sock_client.writeTimeout = 15;
                                   ^.sock_client.readTimeout = 18 ;
                                   ^.sock_client.BufferSize = 256 ;
                                   ^.btnIsCon.PostEvent(new Event("TOUCH"));
                           } else {
                                   var ret = ^.sock_client.getError();
                                   MessageBox("code: " + str(ret.code) + " " + ret.message);
                           }

                   } catch(e) {
                           MessageBox("Message=" + str(e.Message) + "\nCategory=" + str(e.Category) + "\nCode="+ str(e.Code)  + "\nSubCode=" + str(e.subCode));
                   }
           }
   }
   Button btnClose {
           X = 222;
           Y = 89;
           Width = 112;
           Height = 25;
           Title = "切断(Close)";

           Function OnTouch( e ) {
                   try {
                           ^.sock_client.Close(10);
                           ^.btnIsCon.PostEvent(new Event("TOUCH"));
                   } catch(e) {
                           MessageBox("Message=" + str(e.Message) + "\nCategory=" + str(e.Category) + "\nCode="+ str(e.Code)  + "\nSubCode=" + str(e.subCode));
                   }
           }
   }

   Label lblIsCon {
           X = 338;
           Y = 63;
           Width = 69;
           Height = 25;

           Function OnClicked( e ) {
                   this.Clear();
           }
   }
   Button btnIsCon {
           X = 410;
           Y = 63;
           Width = 117;
           Height = 25;
           Title = "IsConnected";

           Function OnTouch( e ) {
                   try {
                           ^.lblIsCon.Value = ^.sock_client.IsConnected ? "接続中" : "切断中";
                   }
                   catch(e) {
                           MessageBox("Message=" + str(e.Message) + "\nCategory=" + str(e.Category) + "\nCode="+ str(e.Code)  + "\nSubCode=" + str(e.subCode));
                   }
           }
   }

   TextBox txtHost2 {
           X = 16;
           Y = 118;
           Width = 340;
           Height = 24;
           Editable = false;
   }
   TextBox txtPort2 {
           X = 357;
           Y = 118;
           Width = 79;
           Height = 24;
           Editable = false;
   }
   TextBox txtBuff2 {
           X = 437;
           Y = 118;
           Width = 78;
           Height = 24;
           Editable = false;
   }
   Button btnGetHost {
           X = 517;
           Y = 114;
           Width = 138;
           Height = 31;
           Title = "Host/Port/Buff取得";
           Function OnTouch( e ) {
                   ^.txtHost2 = ^.sock_client.Host;
                   ^.txtPort2 = ^.sock_client.Port;
                   ^.txtBuff2 = ^.sock_client.BufferSize;
           }
   }

   Label Label4 {
           X = 28;
           Y = 232;
           Width = 78;
           Height = 18;
           Value = "EditBox1";
           TabIndex = 2;
   }
   EditBox txtString {
           X = 28;
           Y = 252;
           Width = 163;
           Height = 70;
           TabIndex = 2;
   }
   Button btnWrite {
           X = 197;
           Y = 250;
           Width = 117;
           Height = 29;
           Title = "送信(Write)";
           Function OnTouch( e ) {
                   try {
                           ^.sock_client.Write(^.txtString.Value);
                   }
                   catch(e) {
                           MessageBox("Message=" + str(e.Message) + "\nCategory=" + str(e.Category) + "\nCode="+ str(e.Code)  + "\nSubCode=" + str(e.subCode));
                   }
           }
   }

   Label Label9 {
           X = 457;
           Y = 230;
           Width = 74;
           Height = 20;
           Value = "受信データ";
   }
   EditBox EdiString2 {
           X = 456;
           Y = 251;
           Width = 163;
           Height = 82;
   }
}