# Trait ethcore_network::NetworkProtocolHandler [−] [src]

    pub trait NetworkProtocolHandler: Sync + Send {
        fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]);
        fn connected(&self, io: &NetworkContext, peer: &PeerId);
        fn disconnected(&self, io: &NetworkContext, peer: &PeerId);

        fn initialize(&self, _io: &NetworkContext) { ... }
        fn timeout(&self, _io: &NetworkContext, _timer: TimerToken) { ... }
    }

Network IO protocol handler. This needs to be implemented for each new subprotocol. All the handler function are called from within IO event loop. `Message` is the type for message data.

## Required Methods

### `fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8])`

Called when new network packet received.

### `fn connected(&self, io: &NetworkContext, peer: &PeerId)`

Called when new peer is connected. Only called when peer supports the same protocol.

### `fn disconnected(&self, io: &NetworkContext, peer: &PeerId)`

Called when a previously connected peer disconnects.

## Provided Methods

### `fn initialize(&self, _io: &NetworkContext)`

Initialize the handler

### `fn timeout(&self, _io: &NetworkContext, _timer: TimerToken)`

Timer function called after a timeout created with `NetworkContext::timeout`.

## Implementors

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)