fn tcp_connect(&mut self, sn: Sn, port: u16, addr: &SocketAddrV4) -> Result<(), Self::Error> {
        debug_assert!(
            port_is_unique(self, sn, port)?,
            "Local port {port} is in use"
        );

        self.set_sn_cr(sn, SocketCommand::Close)?;
        // This will not hang, the socket status will always change to closed
        // after a close command.
        // (unless you do somthing silly like holding the W5500 in reset)
        while self.sn_sr(sn)? != Ok(SocketStatus::Closed) {}

        const MODE: SocketMode = SocketMode::DEFAULT.set_protocol(Protocol::Tcp);
        self.set_sn_mr(sn, MODE)?;
        self.set_sn_port(sn, port)?;
        self.set_sn_cr(sn, SocketCommand::Open)?;
        self.set_sn_dest(sn, addr)?;
        // This will not hang, the socket status will always change to Init
        // after a open command with SN_MR set to TCP.
        // (unless you do somthing silly like holding the W5500 in reset)
        while self.sn_sr(sn)? != Ok(SocketStatus::Init) {}

        self.set_sn_cr(sn, SocketCommand::Connect)
    }
/// Starts the 3-way TCP handshake with the remote host.
///
/// This method is used to create and interact with a TCP stream between
/// a local host and a remote socket.
///
/// After initiating a connection with [`tcp_connect`] and receiving the
/// [`con`] interrupt data can be transmitting by using [`tcp_read`] and
/// [`tcp_write`].
///
/// Calling this method **does not** mean the socket will be connected
/// afterwards, this simply starts the three way handshake.
///
/// After calling this method you will eventually get one of 3 interrupts on
/// the socket:
///
/// 1. [`con`](w5500_ll::SocketInterrupt::con_raised)
/// 2. [`discon`](w5500_ll::SocketInterrupt::discon_raised)
/// 3. [`timeout`](w5500_ll::SocketInterrupt::timeout_raised)
///
/// # Arguments
///
/// * `socket` - The socket number to use for this TCP stream.
/// * `port` - The local port to use for the TCP connection.
/// * `addr` - Address of the remote host to connect to.
///
/// # Panics
///
/// * (debug) The port must not be in use by any other socket on the W5500.
///
/// # Example
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// use w5500_hl::{
///     ll::{Registers, Sn, SocketInterrupt},
///     net::{Ipv4Addr, SocketAddrV4},
///     Tcp,
/// };
///
/// const MQTT_SOCKET: Sn = Sn::Sn0;
/// const MQTT_SOURCE_PORT: u16 = 33650;
/// const MQTT_SERVER: SocketAddrV4 = SocketAddrV4::new(Ipv4Addr::new(192, 168, 2, 10), 1883);
///
/// w5500.tcp_connect(MQTT_SOCKET, MQTT_SOURCE_PORT, &MQTT_SERVER)?;
///
/// // wait for a socket interrupt
/// // you should use the actual interrupt pin, polling is just for demonstration
/// loop {
///     let sn_ir: SocketInterrupt = w5500.sn_ir(MQTT_SOCKET)?;
///
///     // in reality you will want to handle disconnections gracefully with retries
///     assert!(!sn_ir.discon_raised());
///     assert!(!sn_ir.timeout_raised());
///
///     // connection succeded
///     if sn_ir.con_raised() {
///         break;
///     }
/// }
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// ```
///
/// [`tcp_write`]: Tcp::tcp_write
/// [`tcp_read`]: Tcp::tcp_read
/// [`tcp_connect`]: Tcp::tcp_connect
/// [`con`]: w5500_ll::SocketInterrupt::con_raised
Starts the 3-way TCP handshake with the remote host.
This method is used to create and interact with a TCP stream between
a local host and a remote socket.



Calling this method **does not** mean the socket will be connected
afterwards, this simply starts the three way handshake.

After calling this method you will eventually get one of 3 interrupts on
the socket.

1.
Starts the 3 - way TCP handshake with the remote host . This method is used to create and interact with a TCP stream between a local host and a remote socket . Calling this method ** does not ** mean the socket will be connected afterwards this simply starts the three way handshake . After calling this method you will eventually get one of 3 interrupts on the socket . 1 .
fn tcp_connect(&mut self, sn: Sn, port: u16, addr: &SocketAddrV4) -> Result<(), Self::Error> {
        debug_assert!(
            port_is_unique(self, sn, port)?,
            "Local port {port} is in use"
        );
        self.set_sn_cr(sn, SocketCommand::Close)?;
        // This will not hang, the socket status will always change to closed
        // after a close command.
        // (unless you do somthing silly like holding the W5500 in reset)
        while self.sn_sr(sn)? != Ok(SocketStatus::Closed) {}
        const MODE: SocketMode = SocketMode::DEFAULT.set_protocol(Protocol::Tcp);
        self.set_sn_mr(sn, MODE)?;
        self.set_sn_port(sn, port)?;
        self.set_sn_cr(sn, SocketCommand::Open)?;
        self.set_sn_dest(sn, addr)?;
        // This will not hang, the socket status will always change to Init
        // after a open command with SN_MR set to TCP.
        // (unless you do somthing silly like holding the W5500 in reset)
        while self.sn_sr(sn)? != Ok(SocketStatus::Init) {}
        self.set_sn_cr(sn, SocketCommand::Connect)
    }
fn tcp_connect ( & mut self , sn : Sn , port : u16 , addr : & SocketAddrV4 ) -> Result < ( ) , Self :: Error > { debug_assert ! ( port_is_unique ( self sn port ) " " ) ; self . set_sn_cr ( sn , SocketCommand :: Close ) ? ; // This will not hang, the socket status will always change to closed // after a close command. // (unless you do somthing silly like holding the W5500 in reset) while self . sn_sr ( sn ) ? != Ok ( SocketStatus :: Closed ) { } const MODE : SocketMode = SocketMode :: DEFAULT . set_protocol ( Protocol :: Tcp ) ; self . set_sn_mr ( sn , MODE ) ? ; self . set_sn_port ( sn , port ) ? ; self . set_sn_cr ( sn , SocketCommand :: Open ) ? ; self . set_sn_dest ( sn , addr ) ? ; // This will not hang, the socket status will always change to Init // after a open command with SN_MR set to TCP. // (unless you do somthing silly like holding the W5500 in reset) while self . sn_sr ( sn ) ? != Ok ( SocketStatus :: Init ) { } self . set_sn_cr ( sn , SocketCommand :: Connect ) }
Starts the 3-way TCP handshake with the remote host.
Starts the 3 - way TCP handshake with the remote host .
&mut self
sn
Sn
port
u16
addr
&SocketAddrV4
&mut self
sn
Sn
port
u16
addr
&SocketAddrV4
panics
(debug) The port must not be in use by any other socket on the W5500.
( debug ) The port must not be in use by any other socket on the W5500 .
example
None
use embedded_hal_mock as h;
None
let mut w5500 = w5500_ll::blocking::vdm::w5500::new(h::spi::mock::new(&[]), h::pin::mock::new(&[]));
use w5500_hl::{
ll::{Registers, Sn, SocketInterrupt},
net::{Ipv4Addr, SocketAddrV4},
Tcp,
}.



w5500.tcp_connect(MQTT_SOCKET, MQTT_SOURCE_PORT, &MQTT_SERVER)?.

wait for a socket interrupt
you should use the actual interrupt pin, polling is just for demonstration
loop {
let sn_ir: SocketInterrupt = w5500.sn_ir(MQTT_SOCKET)?.

in reality you will want to handle disconnections gracefully with retries
assert!(!sn_ir.discon_raised());
assert!(!sn_ir.timeout_raised()).

connection succeded
if sn_ir.con_raised() {
break;
}
}
use w5500_hl :: { ll :: { Registers Sn SocketInterrupt } net :: { Ipv4Addr SocketAddrV4 } Tcp } . w5500 . tcp_connect ( MQTT_SOCKET MQTT_SOURCE_PORT &MQTT_SERVER ) ? . wait for a socket interrupt you should use the actual interrupt pin polling is just for demonstration loop { let sn_ir : SocketInterrupt = w5500 . sn_ir ( MQTT_SOCKET ) ? . in reality you will want to handle disconnections gracefully with retries assert! ( !sn_ir . discon_raised () ) ; assert! ( !sn_ir . timeout_raised () ) . connection succeded if sn_ir . con_raised () { break ; } }
ok::<(), w5500_hl::ll::blocking::vdm::error<_, _>>(())
None