C# Class BitSharper.NetworkConnection

A NetworkConnection handles talking to a remote BitCoin peer at a low level. It understands how to read and write messages off the network, but doesn't asynchronously communicate with the peer or handle the higher level details of the protocol. After constructing a NetworkConnection, use a Peer to hand off communication to a background thread.
Construction is blocking whilst the protocol version is negotiated.
Inheritance: IDisposable
Show file Open project: TangibleCryptography/BitSharper

Public Methods

Method Description
Dispose ( ) : void
NetworkConnection ( ) : System
NetworkConnection ( IPAddress inetAddress, NetworkParameters @params, uint bestHeight, int connectTimeout ) : System
NetworkConnection ( PeerAddress peerAddress, NetworkParameters @params, uint bestHeight, int connectTimeout ) : System

Connect to the given IP address using the port specified as part of the network parameters. Once construction is complete a functioning network channel is set up and running.

Ping ( ) : void

Sends a "ping" message to the remote node. The protocol doesn't presently use this feature much.

ReadMessage ( ) : Message

Reads a network message from the wire, blocking until the message is fully received.

Shutdown ( ) : void

Shuts down the network socket. Note that there's no way to wait for a socket to be fully flushed out to the wire, so if you call this immediately after sending a message it might not get sent.

ToString ( ) : string
WriteMessage ( Message message ) : void

Writes the given message out over the network using the protocol tag. For a Transaction this should be "tx" for example. It's safe to call this from multiple threads simultaneously, the actual writing will be serialized.

Method Details

Dispose() public method

public Dispose ( ) : void
return void

NetworkConnection() public method

public NetworkConnection ( ) : System
return System

NetworkConnection() public method

public NetworkConnection ( IPAddress inetAddress, NetworkParameters @params, uint bestHeight, int connectTimeout ) : System
inetAddress System.Net.IPAddress
@params NetworkParameters
bestHeight uint
connectTimeout int
return System

NetworkConnection() public method

Connect to the given IP address using the port specified as part of the network parameters. Once construction is complete a functioning network channel is set up and running.
If there is a network related failure. If the version negotiation failed.
public NetworkConnection ( PeerAddress peerAddress, NetworkParameters @params, uint bestHeight, int connectTimeout ) : System
peerAddress PeerAddress IP address to connect to. IPv6 is not currently supported by BitCoin. If port is not positive the default port from params is used.
@params NetworkParameters
bestHeight uint How many blocks are in our best chain
connectTimeout int Timeout in milliseconds when initially connecting to peer
return System

Ping() public method

Sends a "ping" message to the remote node. The protocol doesn't presently use this feature much.
public Ping ( ) : void
return void

ReadMessage() public method

Reads a network message from the wire, blocking until the message is fully received.
If the message is badly formatted, failed checksum or there was a TCP failure.
public ReadMessage ( ) : Message
return Message

Shutdown() public method

Shuts down the network socket. Note that there's no way to wait for a socket to be fully flushed out to the wire, so if you call this immediately after sending a message it might not get sent.
public Shutdown ( ) : void
return void

ToString() public method

public ToString ( ) : string
return string

WriteMessage() public method

Writes the given message out over the network using the protocol tag. For a Transaction this should be "tx" for example. It's safe to call this from multiple threads simultaneously, the actual writing will be serialized.
public WriteMessage ( Message message ) : void
message Message
return void