- GSocket_SetPeer(m_socket, addr_man.GetAddress());
- err = GSocket_Connect(m_socket, GSOCK_STREAMED);
+ // If no local address was passed and one has been set, use the one that was Set
+ if (!local && m_localAddress.GetAddress())
+ {
+ local = &m_localAddress;
+ }
+
+ // Bind to the local IP address and port, when provided
+ if (local)
+ {
+ GAddress* la = local->GetAddress();
+
+ if (la && la->m_addr)
+ m_socket->SetLocal(la);
+ }
+
+ m_socket->SetPeer(addr_man.GetAddress());
+ err = m_socket->Connect(GSOCK_STREAMED);