<?xml version="1.0" encoding="UTF-8" ?>
<feed xml:lang="ja" xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <title type="text">VC++闘いの足跡</title>
  <subtitle type="html">これは心の摘み合いだ。。。</subtitle>
  <link rel="self" type="application/atom+xml" href="https://studyvc.blog.shinobi.jp/atom"/>
  <link rel="alternate" type="text/html" href="https://studyvc.blog.shinobi.jp/"/>
  <updated>2007-07-19T16:16:45+09:00</updated>
  <author><name>No Name Ninja</name></author>
  <generator uri="//www.ninja.co.jp/blog/" version="0.9">忍者ブログ</generator>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" />
  <entry>
    <id>studyvc.blog.shinobi.jp://entry/6</id>
    <link rel="alternate" type="text/html" href="https://studyvc.blog.shinobi.jp/%E6%9C%AA%E9%81%B8%E6%8A%9E/%E3%82%B9%E3%83%AC%E3%83%83%E3%83%89%E3%83%BB%E3%83%BB%E3%83%BB" />
    <published>2007-07-24T09:53:02+09:00</published> 
    <updated>2007-07-24T09:53:02+09:00</updated> 
    <category term="未選択" label="未選択" />
    <title>スレッド・・・</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[課題を簡単にしてもらいました。<br />
<br />
Aボタン押下でスレッド作成、<br />
Bボタン押下でスレッド終了する<br />
<br />
スレッドが殺せない・・・]]> 
    </content>
    <author>
            <name>No Name Ninja</name>
        </author>
  </entry>
  <entry>
    <id>studyvc.blog.shinobi.jp://entry/5</id>
    <link rel="alternate" type="text/html" href="https://studyvc.blog.shinobi.jp/%E6%9C%AA%E9%81%B8%E6%8A%9E/%E7%A7%81%E3%81%AE%E9%A0%AD%E3%81%AE%E4%B8%AD%E3%81%AE%E3%80%82%E3%80%82%E3%80%82" />
    <published>2007-07-23T16:21:22+09:00</published> 
    <updated>2007-07-23T16:21:22+09:00</updated> 
    <category term="未選択" label="未選択" />
    <title>私の頭の中の。。。</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[実現したい機能って、どうやってまとめたらいいんだろ。。。<br />
とりあえず、羅列？？？]]> 
    </content>
    <author>
            <name>No Name Ninja</name>
        </author>
  </entry>
  <entry>
    <id>studyvc.blog.shinobi.jp://entry/4</id>
    <link rel="alternate" type="text/html" href="https://studyvc.blog.shinobi.jp/%E6%9C%AA%E9%81%B8%E6%8A%9E/mainview%E3%81%BE%E3%81%A8%E3%82%81%E3%80%82" />
    <published>2007-07-20T09:30:52+09:00</published> 
    <updated>2007-07-20T09:30:52+09:00</updated> 
    <category term="未選択" label="未選択" />
    <title>MainViewまとめ。</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[①基本クラスはCFormViewクラス。<br />
②スタイル：チャイルド、境界線：なしにする。<br />
③MainViewのﾍｯﾀﾞﾌｧｲﾙをインクルードするのを忘れずに。<br />
④ラインタイム箇所を変更する。]]> 
    </content>
    <author>
            <name>No Name Ninja</name>
        </author>
  </entry>
  <entry>
    <id>studyvc.blog.shinobi.jp://entry/3</id>
    <link rel="alternate" type="text/html" href="https://studyvc.blog.shinobi.jp/%E6%9C%AA%E9%81%B8%E6%8A%9E/mfc%20%E3%82%A2%E3%83%97%E3%83%AA%E3%82%B1%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E5%86%85%E3%81%AE%E3%82%B9%E3%83%AC%E3%83%83%E3%83%89%E9%96%93%E3%81%A7%E3%82%BD%E3%82%B1%E3%83%83%E3%83%88%E6%8E%A5%E7%B6%9A%E3%82%92%E6%B8%A1%E3%81%99%E6%96%B9%E6%B3%95" />
    <published>2007-07-20T09:21:25+09:00</published> 
    <updated>2007-07-20T09:21:25+09:00</updated> 
    <category term="未選択" label="未選択" />
    <title>MFC アプリケーション内のスレッド間でソケット接続を渡す方法</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[<h1 class="title">Visual C++ を使用して MFC アプリケーション内のスレッド間でソケット接続を渡す方法</h1>
<h2 id="tocHeadRef" class="subTitle"><font size="3">------------------------------------------------------------------------------------------------------------------------------------------</font><strong><font size="3"><br />
</font></strong> </h2>
<h2 id="tocHeadRef" class="subTitle">概要</h2>
<script type="text/javascript">loadTOCNode(1, 'summary');</script>
<div class="sbody"> この資料では、MFC アプリケーションのスレッド間でソケット接続を渡す方法をサンプルで示します。サンプルはサーバーとクライアントの 2 つのプロジェクトで構成されています。サーバーは接続ごとに新規スレッドを作成してクライアントと通信します。
<p class="topOfPage"><a href="http://support.microsoft.com/kb/175668/ja#top"><img alt="" src="http://support.microsoft.com/library/images/support/cn/uparrowsrc.gif" />先頭へ戻る</a></p>
</div>
<h2 id="tocHeadRef" class="subTitle">詳細</h2>
<script type="text/javascript">loadTOCNode(1, 'moreinformation');</script>
<h3 id="tocHeadRef"> サーバー </h3>
<script type="text/javascript">loadTOCNode(2, 'moreinformation');</script>
サー バーでは、MFC アプリケーションの複数のスレッドでソケットを使用する方法を示します。サーバーは接続要求を待ちます。新しい接続が要求されるとそれを受け付け、接続を 処理するスレッドを作成します。サーバーがメッセージを受信した場合は、そのメッセージを反転してクライアントに送り返します。 <br />
<br />
MFC では、新しい接続の場合は、リスニング ソケットのあるスレッドで接続を受け付ける必要があります。Accept の呼び出しは CAsyncSocket オブジェクト内で渡す必要があります。その後 MFC により、接続がスレッドで処理されるように、すべての情報が適切にセットアップされます。この接続を別のスレッドで処理する場合は、そのスレッドに MFC オブジェクトを渡すだけでは正常に機能しません。別のスレッドで接続が処理されるようにすべてを適切にセットアップするには、以下の手順を実行する必要が あります。 <br />
<br />
<table class="list ol">
    <tbody>
        <tr>
            <td class="number">1.</td>
            <td class="text"> 接続を受け付けたスレッドで、CAsyncSocket オブジェクトからソケット ハンドルをデタッチします。 </td>
        </tr>
        <tr>
            <td class="number">2.</td>
            <td class="text"> ソケット ハンドルをスレッドに渡します。 </td>
        </tr>
        <tr>
            <td class="number">3.</td>
            <td class="text"> スレッドで、このハンドルを CAsyncSocket 派生オブジェクトにアタッチします。 </td>
        </tr>
    </tbody>
</table>
スレッドの Attach の呼び出しによって、接続を処理するスレッドに送信されるソケット通知にすべての情報が適切にセットアップされます。 <br />
<br />
サーバー プロジェクトから抜き出した次のコードは、これを示したものです。 <br />
<br />
リスニング ソケットでの OnAccept <code></code>
<pre class="code">   void CListensoc::OnAccept(int nErrorCode)<br />   {<br />      // New connection is being established<br /><br />      CSocket soc;<br /><br />      // Accept the connection using a temp CSocket object.<br />      Accept(soc);<br /><br />      // Create a thread to handle the connection.<br />      // The thread is created suspended so that we can<br />      // set variables in CConnectThread before it starts executing.<br />      CConnectThread* pThread =<br />         (CConnectThread*)AfxBeginThread(<br />            RUNTIME_CLASS(CConnectThread),<br />            THREAD_PRIORITY_NORMAL,<br />            0,<br />            CREATE_SUSPENDED);<br />   ...<br />      // Pass the socket to the thread by passing the socket handle.<br />      // You cannot pass a CSocket object across threads.<br />      pThread-&gt;m_hSocket = soc.Detach();<br /><br />      // Now start the thread.<br />      pThread-&gt;ResumeThread();<br /><br />      CAsyncSocket::OnAccept(nErrorCode);<br />   }<br />				</pre>
スレッドの InitInstance <code></code>
<pre class="code">   BOOL CConnectThread::InitInstance()<br />   {<br />   ...<br />      // Attach the socket handle to a CSocket object.<br />      // This makes sure that the socket notifications are sent<br />      // to this thread.<br />      m_socket.Attach(m_hSocket);<br />   ...<br />   }<br />				</pre>
上記のコードにより、ソケットが 2 番目のスレッドに適切にセットアップされます。<br />
------------------------------------------------------------------------------------------------------------------------------------------<br />
<br />
msdnより。<br />
<br />
わかったような、わからないような。。。]]> 
    </content>
    <author>
            <name>No Name Ninja</name>
        </author>
  </entry>
  <entry>
    <id>studyvc.blog.shinobi.jp://entry/2</id>
    <link rel="alternate" type="text/html" href="https://studyvc.blog.shinobi.jp/%E6%9C%AA%E9%81%B8%E6%8A%9E/%E8%AA%B2%E9%A1%8C%EF%BC%91" />
    <published>2007-07-19T16:25:59+09:00</published> 
    <updated>2007-07-19T16:25:59+09:00</updated> 
    <category term="未選択" label="未選択" />
    <title>課題１</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[サーバ１　対　クライアント１　で<br />
メッセージのやりとりをしなさい。]]> 
    </content>
    <author>
            <name>No Name Ninja</name>
        </author>
  </entry>
  <entry>
    <id>studyvc.blog.shinobi.jp://entry/1</id>
    <link rel="alternate" type="text/html" href="https://studyvc.blog.shinobi.jp/%E6%9C%AA%E9%81%B8%E6%8A%9E/%E3%83%86%E3%82%B9%E3%83%88" />
    <published>2007-07-19T16:20:15+09:00</published> 
    <updated>2007-07-19T16:20:15+09:00</updated> 
    <category term="未選択" label="未選択" />
    <title>テスト</title>
    <content mode="escaped" type="text/html" xml:lang="utf-8"> 
      <![CDATA[テスト]]> 
    </content>
    <author>
            <name>No Name Ninja</name>
        </author>
  </entry>
</feed>