I have a real simple application where I want to have a TCP server running on Ubuntu 12.04. I have the following code:
WCServer server;
write
("Able to listen on port: " + QString::number(server.
serverPort()));
} else {
write("Failed to bind to port 3912.");
}
if (server.isListening()) {
write
("Server is Listening on port " + QString::number(server.
serverPort()));
} else {
write("Server is not Listening.");
}
WCServer server;
if (server.listen(QHostAddress::Any, 3912)) {
write("Able to listen on port: " + QString::number(server.serverPort()));
} else {
write("Failed to bind to port 3912.");
}
if (server.isListening()) {
write("Server is Listening on port " + QString::number(server.serverPort()));
} else {
write("Server is not Listening.");
}
To copy to clipboard, switch view to plain text mode
WCServer is a subclass of QTcpServer here is the code for it.
WCServer.h:
#ifndef WCSERVER_H
#define WCSERVER_H
#include <QTcpServer>
#include "clientsocket.h"
#include "mainwindow.h"
#include "globals.h"
{
Q_OBJECT
public:
explicit WCServer
(QObject *parent
= 0);
private:
void incomingConnection(int socketID);
MainWindow *w;
signals:
public slots:
};
#endif // WCSERVER_H
#ifndef WCSERVER_H
#define WCSERVER_H
#include <QTcpServer>
#include "clientsocket.h"
#include "mainwindow.h"
#include "globals.h"
class WCServer : public QTcpServer
{
Q_OBJECT
public:
explicit WCServer(QObject *parent = 0);
private:
void incomingConnection(int socketID);
MainWindow *w;
signals:
public slots:
};
#endif // WCSERVER_H
To copy to clipboard, switch view to plain text mode
This code runs and it say it is listening on port 3912, but when I use any of the following commands it does not show that that port is listening.
sockstat -l
netstat -lnptu
I checked with ufw and the firewall is not on.
I have tried to reach this port both locally and remotely but it always says "connection refused".
I have tried to run the program as sudo thinking "maybe a super user is the only one who can listen" but that makes no difference.
Any help would be greatly appreciated
Bookmarks