PDA

View Full Version : remote port of a socket that hasn't connected yet



spraff
18th November 2008, 12:43
Hi there.

I have created a QTcpSocket and called connectToHost on a given address and port. Later I respond to the stateChanged signal before it's in the ConnectedState state and need to know the address and port the socket is trying to connect to. Unfortunately while peerName remembers who connectToHost was referring to, peerPort returns zero until after the connection has been made.

Apart from being irritatingly inconsistent, is there another way to fetch the port as passed to connectToHost? Storing a copy elsewhere breaks my encapsulation :(

wysota
18th November 2008, 17:24
Well... if the socket doesn't know what it is connecting to, it is hard for it to return a real value. If you are the active (connecting) socket, you should know where you connect to or you can store this information in the socket object if you want.