selectは、複数のファイルディスクリプタを監視し、なんらかの状態変化が発生した場合に、この関数を抜けることで知らせるWindowsAPI・・・。
UNIX系OS同様にWindowsでも、これでマルチセッションが出来る・・・。
サーバ側はselectプロジェクトを作成し、クライアント側はsendプロジェクトを使う・・・。
send.cppのメッセージ処理ループは、
select.cppのアクセプトループは、
という感じ・・・。
selectプロジェクトをスタートアッププロジェクトにして、実行すると、
WSAStartup success! soc = 124 port = 0fa0, ns_port = a00f setsockopt(SO_REUSEADDR) success. bind Success. listen success. count = 0 timeout! count = 0 timeout! count = 0 timeout! count = 0 timeout! count = 0 timeout! count = 0 timeout! count = 0
send.exeで接続して、"hoge"を入力・・・。
WSAStartup success! hostname: localhost port: 4000 host->h_addr_list[0][0] = 7f, host->h_addr_list[0][1] = 00, host->h_addr_list[0] [3] = 00, host->h_addr_list[0][3] = 01 soc = 360 port = 0fa0, ns_port = a00f connect success. >hoge >
select.exeには、
accept!(IPAddress = 127.0.0.1, Port = 50590) count = 1 hoge count = 1 timeout!
別のコンソールでsend.exeを実行し、"foobar"を入力・・・。
WSAStartup success! hostname: localhost port: 4000 host->h_addr_list[0][0] = 7f, host->h_addr_list[0][1] = 00, host->h_addr_list[0] [3] = 00, host->h_addr_list[0][3] = 01 soc = 360 port = 0fa0, ns_port = a00f connect success. >foobar >
select.exeには、
count = 1 timeout! count = 1 accept!(IPAddress = 127.0.0.1, Port = 50602) count = 2 timeout! count = 2 timeout! count = 2 foobar count = 2 timeout! count = 2
と出る・・・。
Sample/select.cpp at master · bg1bgst333/Sample · GitHub
Sample/send.cpp at master · bg1bgst333/Sample · GitHub