PDA

View Full Version : connectToHost() resets local port number specified by bind



mohammad.meo
11th November 2014, 23:35
hello!

I try to connect to a server as tcp from client and bind(enter the port for the client), but after I connect to the host (used connecttoHost() method ) in the client
the port changed.
QT client:

Socket->bind(QHostAddress("localhost"),2555);

Socket->connectToHost(QHostAddress::LocalHost,1458);



there is any method or approach to make the port for the client fix ??

wysota
12th November 2014, 00:22
The client always uses a dynamically chosen TCP port. Why would you want to fix it?

mohammad.meo
12th November 2014, 00:44
I'm implementing chat application and I want from client to be able to enter the port for him from textedit

anda_skoa
12th November 2014, 08:20
Why would a user want that? It is entirely irrelevant to the functionality they consume (chatting).

Cheers,
_

mohammad.meo
12th November 2014, 21:35
You're right.
However,I need the client enter port to bind UDP connect,but I used the tcp to send the online client.It was my error I tried used the same port for tcp_socket and udp_socket.
thanks a lot!:)