サンプル集 |
■VC ■C# ■Java ■LinuxC ■MS-DOS ■bash ■Excel VBA ■VBScript ■PHP ■HTML ■perl ■iPhone ■Android ■Lua ■other |
Linuxコマンド |
debian メモ |
apache2 メモ |
MySQL メモ |
Oracle メモ |
HOME |
通信プログラムのサーバー側に、0バイトメッセージの送信を追加しました。
◆環境OS | Linux obsax3 3.0.6 #1 SMP Fri Nov 16 11:53:45 JST 2012 armv7l GNU/Linux |
---|---|
gcc | 4.4.5 (Debian 4.4.5-8) |
処理番号 2に0バイトメッセージの送信を追加しました。
LC114Server.c | ||
|
メイクファイルです。
makefile | ||
|
まずはサーバーを起動し、続いてクライアントを起動し両方とも処理番号入力待ちにします。 この状態でクライアントを 1 で受信待ち状態にします。
15:24:23 CL LC113Client START
15:24:23 CL connect OK
15:24:23 CL ----------------------------------
15:24:23 CL (1) recv message(wait)
15:24:23 CL (2) recv message(don't wait)
15:24:23 CL (9) end
15:24:23 CL input number: 1
15:24:23 CL connect OK
15:24:23 CL ----------------------------------
15:24:23 CL (1) recv message(wait)
15:24:23 CL (2) recv message(don't wait)
15:24:23 CL (9) end
15:24:23 CL input number: 1
サーバー側で 2 (0バイトメッセージの送信)をします。
15:24:23 SV input number: 2
15:26:32 SV send OK!!
15:26:32 SV ----------------------------------
15:26:32 SV (1) send messase
15:26:32 SV (2) send messase (0byte)
15:26:32 SV (9) end
15:26:32 SV input number:
15:26:32 SV send OK!!
15:26:32 SV ----------------------------------
15:26:32 SV (1) send messase
15:26:32 SV (2) send messase (0byte)
15:26:32 SV (9) end
15:26:32 SV input number:
正常に送信できたようです。 ですが、クライアント側はメッセージの受信待ちのままでした。 サーバー側で 1 で普通にメッセージを送信したところ、クライアント側で受信しました。 0バイトのメッセージはどこかで無くなっているようです。 元から0バイト=無いも同然なので、送信できないのでしょうか。
複数メッセージ送信
サーバーとクライアントを接続後、サーバーで3回メッセージを送信します。
17:16:30 SV LC114Server START
17:16:30 SV 接続を待っています
17:16:31 SV accept OK
17:16:31 SV ----------------------------------
17:16:31 SV (1) send messase
17:16:31 SV (2) send messase (0byte)
17:16:31 SV (9) end
17:16:31 SV input number: 1
17:16:32 SV send OK!!
17:16:32 SV ----------------------------------
17:16:32 SV (1) send messase
17:16:32 SV (2) send messase (0byte)
17:16:32 SV (9) end
17:16:32 SV input number: 1
17:16:33 SV send OK!!
17:16:33 SV ----------------------------------
17:16:33 SV (1) send messase
17:16:33 SV (2) send messase (0byte)
17:16:33 SV (9) end
17:16:33 SV input number: 1
17:16:33 SV send OK!!
17:16:33 SV ----------------------------------
17:16:33 SV (1) send messase
17:16:33 SV (2) send messase (0byte)
17:16:33 SV (9) end
17:16:33 SV input number:
17:16:30 SV 接続を待っています
17:16:31 SV accept OK
17:16:31 SV ----------------------------------
17:16:31 SV (1) send messase
17:16:31 SV (2) send messase (0byte)
17:16:31 SV (9) end
17:16:31 SV input number: 1
17:16:32 SV send OK!!
17:16:32 SV ----------------------------------
17:16:32 SV (1) send messase
17:16:32 SV (2) send messase (0byte)
17:16:32 SV (9) end
17:16:32 SV input number: 1
17:16:33 SV send OK!!
17:16:33 SV ----------------------------------
17:16:33 SV (1) send messase
17:16:33 SV (2) send messase (0byte)
17:16:33 SV (9) end
17:16:33 SV input number: 1
17:16:33 SV send OK!!
17:16:33 SV ----------------------------------
17:16:33 SV (1) send messase
17:16:33 SV (2) send messase (0byte)
17:16:33 SV (9) end
17:16:33 SV input number:
続いてクライアント側で受信します。 今回は 2 の don't wait で受信してみます。
17:18:00 CL recv=[send server!!send server!!send server!!] len=[39] errno=[0] msg=[Success]
17:18:00 CL ----------------------------------
17:18:00 CL (1) recv message(wait)
17:18:00 CL (2) recv message(don't wait)
17:18:00 CL (9) end
17:18:00 CL input number:
17:18:00 CL ----------------------------------
17:18:00 CL (1) recv message(wait)
17:18:00 CL (2) recv message(don't wait)
17:18:00 CL (9) end
17:18:00 CL input number:
3回分のメッセージをまとめて受信しました。 recv は send の回数分受信するわけではないようです。 この場合、サーバーは3回 send したので、3回メッセージを送ったと思っていますが、 クライアント側は recv 1回なので、長いメッセージを1回だけ受信したと思っています。
「メッセージはまとまって受信する可能性がある」という事を認識してプログラムを書くように注意が必要ですね。
Copyright (C) 2013 ymlib.com