#include <QtCore/QCoreApplication>
#include "my_socket_handler.h"
int main(int argc, char **argv)
{
while(1)
{
check_for_and_receive_incoming_data_over_sockets();
app.processEvents();
}
return 0;
}
#include <QtCore/QCoreApplication>
#include "my_socket_handler.h"
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
while(1)
{
check_for_and_receive_incoming_data_over_sockets();
app.processEvents();
}
return 0;
}
To copy to clipboard, switch view to plain text mode
#include <QCoreApplication>
#include <QSocketNotifier>
#include <QtDebug>
#include <WinSock2.h>
#include <WS2tcpip.h>
#pragma comment (lib, "Ws2_32.lib")
#include <iostream>
using std::cout;
using std::endl;
#define DEFAULT_PORT "5"
#define DEFAULT_HOST_ADDR "10.10.10.126"
#define DEFAULT_BUF_LEN 512
class RawSocketReader
: public QObject{
Q_OBJECT
public slots:
void doSomething(int socket)
{
char buff[DEFAULT_BUF_LEN];
int length;
while ((length = recv(socket, buff, DEFAULT_BUF_LEN, 0)) >= 0) {
qDebug() << "Received" << length << "bytes";
}
}
};
// ??also, what the heck does this do and where does it live??
#include "main.moc"
int main(int argc, char *argv[]) {
int app_ret_val = 0;
WSADATA wsa_data;
struct addrinfo *result_ptr = 0;
struct addrinfo hints;
SOCKET my_socket = INVALID_SOCKET;
int rx_byte_count = 0;
char rx_buf[DEFAULT_BUF_LEN];
// initialize WSA stuff
WSAStartup(MAKEWORD(2, 2), &wsa_data);
// set up the "hints" struct that will guide the search for
// the host
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
getaddrinfo("10.10.10.126", "5", &hints, &result_ptr);
my_socket = socket(
result_ptr->ai_family,
result_ptr->ai_socktype,
result_ptr->ai_protocol);
connect(
my_socket,
result_ptr->ai_addr,
(int)(result_ptr->ai_addrlen));
RawSocketReader reader;
& notifier,
SIGNAL(activated(int)),
&reader,
SLOT(doSomething(int)));
app_ret_val = app.exec();
closesocket(my_socket);
my_socket = INVALID_SOCKET;
freeaddrinfo(result_ptr);
WSACleanup();
return app_ret_val;
}
#include <QCoreApplication>
#include <QSocketNotifier>
#include <QtDebug>
#include <WinSock2.h>
#include <WS2tcpip.h>
#pragma comment (lib, "Ws2_32.lib")
#include <iostream>
using std::cout;
using std::endl;
#define DEFAULT_PORT "5"
#define DEFAULT_HOST_ADDR "10.10.10.126"
#define DEFAULT_BUF_LEN 512
class RawSocketReader : public QObject
{
Q_OBJECT
public slots:
void doSomething(int socket)
{
char buff[DEFAULT_BUF_LEN];
int length;
while ((length = recv(socket, buff, DEFAULT_BUF_LEN, 0)) >= 0) {
qDebug() << "Received" << length << "bytes";
}
}
};
// ??also, what the heck does this do and where does it live??
#include "main.moc"
int main(int argc, char *argv[]) {
int app_ret_val = 0;
QCoreApplication app(argc, argv);
WSADATA wsa_data;
struct addrinfo *result_ptr = 0;
struct addrinfo hints;
SOCKET my_socket = INVALID_SOCKET;
int rx_byte_count = 0;
char rx_buf[DEFAULT_BUF_LEN];
// initialize WSA stuff
WSAStartup(MAKEWORD(2, 2), &wsa_data);
// set up the "hints" struct that will guide the search for
// the host
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
getaddrinfo("10.10.10.126", "5", &hints, &result_ptr);
my_socket = socket(
result_ptr->ai_family,
result_ptr->ai_socktype,
result_ptr->ai_protocol);
connect(
my_socket,
result_ptr->ai_addr,
(int)(result_ptr->ai_addrlen));
QSocketNotifier notifier(my_socket, QSocketNotifier::Read);
RawSocketReader reader;
QObject::connect(
& notifier,
SIGNAL(activated(int)),
&reader,
SLOT(doSomething(int)));
app_ret_val = app.exec();
closesocket(my_socket);
my_socket = INVALID_SOCKET;
freeaddrinfo(result_ptr);
WSACleanup();
return app_ret_val;
}
To copy to clipboard, switch view to plain text mode
Bookmarks