pub struct P2PSpectatorSession<A: Eq = SocketAddr> { /* private fields */ }
Expand description

A P2PSpectatorSession provides a UDP protocol to connect to a remote host in a peer-to-peer fashion. The host will broadcast all confirmed inputs to this session. This session can be used to spectate a session without contributing to the game input.

Implementations

Creates a new P2PSpectatorSession for a spectator. The session will receive inputs from all players from the given host directly.

Example
let local_port: u16 = 7777;
let num_players : u32 = 2;
let input_size : usize = std::mem::size_of::<u32>();
let host_addr: SocketAddr = "127.0.0.1:8888".parse()?;
let mut session = P2PSpectatorSession::new(num_players, input_size, local_port, host_addr)?;

The created session will use the default socket type (currently UDP).

Errors
  • Will return SocketCreationFailed if the socket could not be created.

Creates a new P2PSpectatorSession for a spectator. The session will receive inputs from all players from the given host directly. The session will use the provided socket.

Returns the current SessionState of a session.

Returns the number of frames behind the host

Sets the amount of frames the spectator advances in a single advance_frame() call if it is too far behind the host. If set to 1, the spectator will never catch up.

Sets the amount of frames behind the host before starting to catch up

Used to fetch some statistics about the quality of the network connection.

Errors
  • Returns NotSynchronized if the session is not connected to other clients yet.

Returns all events that happened since last queried for events. If the number of stored events exceeds MAX_EVENT_QUEUE_SIZE, the oldest events will be discarded.

A spectator can directly start the session. Then, the synchronization process will begin.

Errors
  • Returns InvalidRequest if the session has already been started.

You should call this to notify GGRS that you are ready to advance your gamestate by a single frame. Returns an order-sensitive Vec<GGRSRequest>. You should fulfill all requests in the exact order they are provided. Failure to do so will cause panics later.

Errors
  • Returns NotSynchronized if the session is not yet ready to accept input. In this case, you either need to start the session or wait for synchronization between clients.

Receive UDP packages, distribute them to corresponding UDP endpoints, handle all occurring events and send all outgoing UDP packages. Should be called periodically by your application to give GGRS a chance to do internal work like packet transmissions.

Returns the number of players this session was constructed with.

Returns the input size this session was constructed with.

Sets the FPS this session is used with. This influences ping estimates.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.