<p><code>CNode</code> has a method <code>SocketSendData()</code> which pushes all the serialized data into the socket.</p>

<p><a href="https://github.com/bitcoin/bitcoin/search?utf8=%E2%9C%93&amp;q=SocketSendData&amp;type=Code" rel="nofollow">https://github.com/bitcoin/bitcoin/search?utf8=%E2%9C%93&amp;q=SocketSendData&amp;type=Code</a></p>

CC BY-SA 3.0
2015-12-27T07:50:06.540Z
2015-12-27T07:50:06.540Z
visweshn92
<p>I am curious to know how and where in the source code, the data from stream is actually sent by a node. As per my understanding the following occurs:</p>

<ul>
<li><code>ProcessMessage()</code> issues a <code>PushMessage()</code> with appropriate parameters</li>
<li><code>PushMessage()</code> will basically send message headers and parameters into a stream <code>ssData</code></li>
<li><code>ssData</code> is object of <code>CDataStream</code> and defined in <code>CNode</code></li>
<li><code>CDataStream</code> is in <code>src/stream.h</code> has no information related to IP or Port</li>
</ul>

<p>How does the data being pushed to a stream goes into the correct socket in bitcoin working. Only <code>CNode</code> class has information on the network address (IP) and TCP Port. How is this information picked up by the datastream? </p>

<p><strong>Adding more findings:</strong></p>

<p>I found this from <a href="https://bitcointalk.org/index.php?topic=41727.0" rel="nofollow">https://bitcointalk.org/index.php?topic=41727.0</a></p>

<pre><code>The socket thread reads the sockets and places data into a CDataStream
associated with each node called vRecv. The Satoshi client uses C++
serialization operators &gt;&gt; and &lt;&lt; to read and write to a CDataStream
and then it uses generic routines to move the data between the streams
and sockets
</code></pre>

<p>My exact question is where(what) are these mentioned generic routines in source code?</p>

<bitcoind><bitcoin-core>
How does CDataStream data find its way into a socket?
Paarth
# How does CDataStream data find its way into a socket?

(Asked by: username_0 on 2015-12-27)

I am curious to know how and where in the source code, the data from stream is actually sent by a node. As per my understanding the following occurs:

ProcessMessage() issues a PushMessage() with appropriate parameters
PushMessage() will basically send message headers and parameters into a stream ssData
ssData is object of CDataStream and defined in CNode
CDataStream is in src/stream.h has no information related to IP or Port

How does the data being pushed to a stream goes into the correct socket in bitcoin working. Only CNode class has information on the network address (IP) and TCP Port. How is this information picked up by the datastream? 
Adding more findings:
I found this from https://bitcointalk.org/index.php?topic=41727.0
The socket thread reads the sockets and places data into a CDataStream
associated with each node called vRecv. The Satoshi client uses C++
serialization operators >> and << to read and write to a CDataStream
and then it uses generic routines to move the data between the streams
and sockets

My exact question is where(what) are these mentioned generic routines in source code?

**Tags:** bitcoind, bitcoin-core


---

## 1 answers

### Answer by username_1 on 2015-12-27. Score: 4 | Accepted answer

`CNode` has a method `SocketSendData()` which pushes all the serialized data into the socket.

<https://github.com/bitcoin/bitcoin/search?utf8=%E2%9C%93&q=SocketSendData&type=Code>


---

