<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://en.zaoniao.it/index.php?action=history&amp;feed=atom&amp;title=Satoshi_Client_Sockets_and_Messages</id>
	<title>Satoshi Client Sockets and Messages - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://en.zaoniao.it/index.php?action=history&amp;feed=atom&amp;title=Satoshi_Client_Sockets_and_Messages"/>
	<link rel="alternate" type="text/html" href="http://en.zaoniao.it/index.php?title=Satoshi_Client_Sockets_and_Messages&amp;action=history"/>
	<updated>2026-05-15T09:26:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>http://en.zaoniao.it/index.php?title=Satoshi_Client_Sockets_and_Messages&amp;diff=6746&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;The original bitcoin client uses a multithreaded approach to socket handling and messages processing. There is one thread that handles socket communication (ThreadSocketHandle...&quot;</title>
		<link rel="alternate" type="text/html" href="http://en.zaoniao.it/index.php?title=Satoshi_Client_Sockets_and_Messages&amp;diff=6746&amp;oldid=prev"/>
		<updated>2019-07-10T06:12:29Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;The original bitcoin client uses a multithreaded approach to socket handling and messages processing. There is one thread that handles socket communication (ThreadSocketHandle...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The original bitcoin client uses a multithreaded approach to socket&lt;br /&gt;
handling and messages processing. There is one thread that handles&lt;br /&gt;
socket communication (ThreadSocketHandler) and one (ThreadMessageHandler)&lt;br /&gt;
which handles pulling messages off sockets and calling the&lt;br /&gt;
processing routines. Both of these threads are in [https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp net.cpp].&lt;br /&gt;
The message processing routines are in [https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp main.cpp], however.&lt;br /&gt;
&lt;br /&gt;
==Socket Thread==&lt;br /&gt;
The socket thread reads the sockets and places data into a CDataStream&lt;br /&gt;
associated with each node called vRecv. The Satoshi client uses C++&lt;br /&gt;
serialization operators &amp;amp;gt;&amp;amp;gt; and &amp;amp;lt;&amp;amp;lt; to read and write to a CDataStream&lt;br /&gt;
and then it uses generic routines to move the data between the streams&lt;br /&gt;
and sockets.&lt;br /&gt;
&lt;br /&gt;
==Message Thread==&lt;br /&gt;
The message thread reads and processes all messages from each node in&lt;br /&gt;
sequence, and then it sends messages to each node that should be sent&lt;br /&gt;
messages. That is all it does.&lt;br /&gt;
&lt;br /&gt;
Specifically, ThreadMessageHandler2 calls ProcessMessages(), which is&lt;br /&gt;
located in [https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp main.cpp], to pull messages off each node's socket and&lt;br /&gt;
process them. Then it calls SendMessages(), which is also located&lt;br /&gt;
in [https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp main.cpp] to create and send any messages appropriate for each node.&lt;br /&gt;
&lt;br /&gt;
ProcessMessages() attempts to find a message start signature in the&lt;br /&gt;
vRecv stream. If it finds a message start, it deletes everything&lt;br /&gt;
prior to the start. Then it reads the header, extracts the message&lt;br /&gt;
type, and calls ProcessMessage on the message.&lt;br /&gt;
&lt;br /&gt;
SendMessages() actually creates and sends messages; it does not&lt;br /&gt;
just send preexisting queued messages. It goes through various&lt;br /&gt;
maps looking for work to do and produces a message and calls&lt;br /&gt;
PushMessage method of CNode to send the message. PushMessage&lt;br /&gt;
queues outbound data in the vSend data stream. (See PushMessage() in&lt;br /&gt;
[https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp net.cpp]). The socket thread handler then pulls data off the&lt;br /&gt;
vSend data stream and calls send on the socket to send the data.&lt;br /&gt;
&lt;br /&gt;
==Source==&lt;br /&gt;
&lt;br /&gt;
[http://bitcoin.it/ http://bitcoin.it/]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technology]]&lt;br /&gt;
[[Category:Manuals]]&lt;br /&gt;
==See Also on BitcoinWiki==&lt;br /&gt;
* [[ServAdvisor]]&lt;br /&gt;
* [[Litebolt]]&lt;br /&gt;
* [[Realista]]&lt;br /&gt;
* [[ImmVRse]]&lt;br /&gt;
* [[AQUA]]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
		
	</entry>
</feed>