I have a small program I created. Here is a relevant piece of it:
void TcpSocket::ConnectSocket()
{
socket = new QTcpSocket(this);
socket->connectToHost("localhost", 77);
if(socket->waitForConnected(3000)){
qDebug() << "Connected";
socket->write("Hello Server
");
socket->waitForBytesWritten(1000);
socket->waitForReadyRead(3000);
qDebug() << "Reading: " << socket->bytesAvailable();
qDebug() << socket->readAll();
socket->close();
}
else {
qDebug() << "Could not connect";
}
}
Basically, I want to open a tcp socket at localhost:77. I want to write some data to it, get a response, and then output the response. However, right now that port is closed, as most ports are in ubuntu by default. So right now it cannot connect to that port to listen on. Well from what I researched, iptables seems to be the only way to open a port for listening. So I run this line on my machine:
sudo iptables -A INPUT -p tcp --dport 77 -j ACCEPT
However, the port 77 is still not open.
sudo netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 1199/dnsmasq
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1004/cupsd
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1157/postgres
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1121/mysqld
tcp6 0 0 ::1:631 :::* LISTEN 1004/cupsd
udp 0 0 127.0.0.1:53 0.0.0.0:* 1199/dnsmasq
udp 0 0 0.0.0.0:68 0.0.0.0:* 1070/dhclient
udp 0 0 0.0.0.0:39617 0.0.0.0:* 990/avahi-daemon: r
udp 0 0 0.0.0.0:5353 0.0.0.0:* 990/avahi-daemon: r
udp6 0 0 :::57021 :::* 990/avahi-daemon: r
udp6 0 0 :::5353 :::* 990/avahi-daemon: r
netstat doesnt show it to be open. Also I still have the same problem with my program: it cannot connect to 77.