Commit c5cc8057 authored by Andreas Kempe's avatar Andreas Kempe

Work on the networking. Implemented a socket server side.

parent 450855a3
# Generated by YCM Generator at 2015-10-02 00:15:03.628219
# Generated by YCM Generator at 2015-10-02 17:50:02.654563
# This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
......@@ -38,15 +38,24 @@ flags = [
'c++',
'-DMAGICKCORE_HDRI_ENABLE=0',
'-DMAGICKCORE_QUANTUM_DEPTH=16',
'-I/home/andkem/Dokument/Programmering/mpi-mandelbrot',
'-DQT_CORE_LIB',
'-DQT_GUI_LIB',
'-DQT_NETWORK_LIB',
'-DQT_NO_DEBUG',
'-DQT_WIDGETS_LIB',
'-I/home/andkem/Program/imagemagick/include/ImageMagick-6',
'-I/home/andkem/Program/openmpi/include',
'-I/home/kempe/Documents/Programmering/mpi-mandelbrot',
'-I/home/kempe/lib/include',
'-I/home/kempe/lib/include/ImageMagick-6',
'-I/tmp/tmpyfGoxK',
'-I/tmp/tmps_s0z8',
'-I/usr/include/qt5',
'-I/usr/include/qt5/QtCore',
'-I/usr/include/qt5/QtGui',
'-I/usr/include/qt5/QtNetwork',
'-I/usr/include/qt5/QtWidgets',
'-I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64',
'-std=c++11',
'-I/home/andkem/Program/Qt/5.5/gcc_64/include/QWidgets',
'-I/home/andkem/Program/Qt/5.5/gcc_64/include/QGui',
'-I/home/andkem/Program/Qt/5.5/gcc_64/include/QNetwork',
'-I/home/kempe/Documents/Programmering/mpi-mandelbrot/network',
]
......
project(mpi-mandel)
cmake_minimum_required(VERSION 3.3.2)
cmake_minimum_required(VERSION 2.8.3)
# Qt-stuff
set(CMAKE_AUTOMOC ON)
......@@ -10,11 +10,13 @@ find_package(Qt5Gui)
find_package(Qt5Network)
# Source files
set(SERVER_SRC server/main.cpp server/mandelbrot.cpp)
set(SERVER_SRC server/main.cpp server/mandelbrot.cpp server/server_socket.cpp)
set(CLIENT_SRC client/main.cpp client/main_window.cpp)
set(MANDELNET_SRC network/data_packet.cpp)
include_directories(/home/andkem/Program/imagemagick/include/ImageMagick-6
/home/kempe/lib/include/ImageMagick-6
network
${Qt5Widgets_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Network_INCLUD_DIRS})
......@@ -23,6 +25,7 @@ include_directories(/home/andkem/Program/imagemagick/include/ImageMagick-6
# Executables
add_executable(mpi-mandel-srv ${SERVER_SRC})
add_executable(mandel-clt ${CLIENT_SRC})
add_library(mandelnet ${MANDELNET_SRC})
find_library(Magick Magick++-6.Q16
......@@ -30,10 +33,10 @@ find_library(Magick Magick++-6.Q16
/home/kempe/lib/lib)
# Set the MPI compilers
set(CMAKE_C_COMPILER /home/andkem/Program/openmpi/bin/mpicc)
set(CMAKE_CXX_COMPILER /home/andkem/Program/openmpi/bin/mpicxx)
set(CMAKE_C_COMPILER mpicc)
set(CMAKE_CXX_COMPILER mpicxx)
set(CMAKE_CXX_FLAGS "-DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -O3 -std=c++11 -fPIC")
# Libraries
target_link_libraries(mpi-mandel-srv mpi ${Magick})
target_link_libraries(mpi-mandel-srv mpi ${Magick} Qt5::Network mandelnet)
target_link_libraries(mandel-clt Qt5::Widgets Qt5::Gui Qt5::Network)
#include "main_window.h"
#include "network_defines.h"
#include <QApplication>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
main_window wnd(nullptr);
main_window wnd(PORT, nullptr);
wnd.show();
return app.exec();
......
......@@ -2,8 +2,8 @@
#include <QPixmap>
#include <QPushButton>
main_window::main_window(QWidget* parent) :
QWidget(parent)
main_window::main_window(unsigned int port, QWidget* parent) :
port(port), QWidget(parent)
{
mandel_image = new QImage("output.png");//(1064, 800, QImage::Format_RGB30);
......@@ -23,7 +23,7 @@ main_window::main_window(QWidget* parent) :
server = new QTcpServer(this);
connect(server, &QTcpServer::newConnection, this, &main_window::handle_new_connection);
server->listen(QHostAddress::Any, 8910);
server->listen(QHostAddress::Any, port);
}
main_window::~main_window()
......@@ -42,6 +42,7 @@ void main_window::handle_new_connection()
socket = server->nextPendingConnection();
connect(socket, &QTcpSocket::disconnected, this, &main_window::handle_socket_close);
connect(socket, &QTcpSocket::readyRead, this, &main_window::handle_recv_data);
// Close the server since we only want one connection at a time.
server->close();
......@@ -51,5 +52,9 @@ void main_window::handle_socket_close()
{
socket->deleteLater();
// If we lose the cluster process we start listening again.
server->listen();
server->listen(QHostAddress::Any, port);
}
void main_window::handle_recv_data()
{
}
......@@ -12,7 +12,7 @@ class main_window : public QWidget
{
Q_OBJECT
public:
main_window(QWidget* parent);
main_window(unsigned int port, QWidget* parent);
~main_window();
private:
......@@ -25,10 +25,15 @@ class main_window : public QWidget
QTcpServer* server;
QTcpSocket* socket;
const unsigned int port;
public slots:
void show_image();
private slots:
void handle_new_connection();
void handle_socket_close();
void handle_recv_data();
};
......
#include "data_packet.h"
data_packet::data_packet(op_codes op_code, size_t payload_size, char* payload) :
op_code(static_cast<quint32>(op_code)), payload_size(payload_size), payload(payload)
{
}
data_packet::~data_packet()
{
delete payload;
}
QDataStream& operator<<(QDataStream& stream, const data_packet& packet)
{
stream << packet.op_code;
stream.writeRawData(packet.payload, packet.payload_size);
return stream;
}
#ifndef DATA_PACKET_H
#define DATA_PACKET_H
#include <QDataStream>
enum class op_codes : quint32
{
TEST = 0x00000000
};
class data_packet
{
friend QDataStream& operator<<(QDataStream&, const data_packet&);
public:
// The user is responsible for allocating memory for payload.
// data_packet will then call delete on it in its constructor.
data_packet(op_codes op_code, size_t payload_size, char* payload);
~data_packet();
private:
quint32 op_code;
size_t payload_size;
char* payload;
};
QDataStream& operator<<(QDataStream& stream, const data_packet& packet);
#endif
#ifndef NETWORK_DEFINES_H
#define NETWORK_DEFINES_H
#define PORT 8910
#endif
#include "mandelbrot.h"
#include "server_socket.h"
#include "network_defines.h"
#include "data_packet.h"
#include <mpi.h>
#include <iostream>
#include <Magick++.h>
......@@ -60,6 +63,10 @@ int main(int argc, char** argv)
unsigned long *calculated_values;
unsigned long *receive_buffer = nullptr;
server_socket socket("127.0.0.1", PORT, nullptr);
data_packet(op_codes::TEST, 0, nullptr);
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &procs);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
......
#include "server_socket.h"
#include <QDebug>
using namespace std;
server_socket::server_socket(QString host, unsigned int port, QObject* parent)
{
connect(this, &QTcpSocket::readyRead, this, &server_socket::handle_recv_data);
connectToHost(host, port, QIODevice::ReadWrite, QAbstractSocket::AnyIPProtocol);
}
void server_socket::handle_recv_data()
{
qDebug() << "Received data!";
}
#ifndef SERVER_SOCKET_H
#define SERVER_SOCKET_H
#include <QTcpSocket>
class server_socket : public QTcpSocket
{
Q_OBJECT
public:
server_socket(QString host, unsigned int port, QObject* parent);
private slots:
void handle_recv_data();
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment