writeline
説明
例
リモート ホストからの ASCII データ行の読み取りと書き込み
t
という TCP/IP クライアント接続を作成します。TCP/IP エコー サーバーにポート 4000 で接続します。そのためには、echotcpip
サーバーをポート 4000 で実行していなければなりません。
echotcpip("on",4000) t = tcpclient("localhost",4000)
t = tcpclient with properties: Address: 'localhost' Port: 4000 NumBytesAvailable: 0 Show all properties, functions
既定の ASCII 終端子をチェックします。
t.Terminator
ans = "LF"
終端子を "CR"
に設定し、ASCII データの文字列を書き込みます。関数 writeline
は、終端子をデータに自動的に追加します。
configureTerminator(t,"CR") writeline(t,"hello")
終端子が自動的に追加された別の ASCII データの文字列を書き込みます。
writeline(t,"world")
クライアントはエコー サーバーに接続しているため、サーバーに書き込むデータはクライアントに返されます。ASCII データ文字列を読み取ります。関数 readline
は、終端子に到達するまでデータを返します。
readline(t)
ans = "hello"
ASCII データ文字列をもう一度読み取り、書き込んだ 2 つ目の文字列を返します。
readline(t)
ans = "world"
エコー サーバーを閉じ、TCP/IP クライアント接続をクリアします。
echotcpip("off") clear t
入力引数
t
— TCP/IP クライアント
tcpclient
オブジェクト
TCP/IP クライアント。tcpclient
オブジェクトとして指定します。
例: writeline(t,data)
は、ASCII データを TCP/IP クライアント t
に書き込みます。
data
— ASCII データ
文字ベクトル | string スカラー
書き込む ASCII データ。テキストの文字ベクトルまたは string スカラーとして指定します。
例: writeline(t,"helloworld")
は、ASCII データ "helloworld"
を書き込みます。
データ型: char
| string
バージョン履歴
R2020b で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)