This commit is contained in:
lotodore
2007-02-25 23:33:55 +00:00
parent d4855a2ca2
commit a046ba0e95
2 changed files with 129 additions and 129 deletions
@@ -1,109 +1,109 @@
/*************************************************************************** /***************************************************************************
* Copyright (C) 2006 by FThauer FHammer * * Copyright (C) 2006 by FThauer FHammer *
* f.thauer@web.de * * f.thauer@web.de *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
* This program is distributed in the hope that it will be useful, * * This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. * * GNU General Public License for more details. *
* * * *
* You should have received a copy of the GNU General Public License * * You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the * * along with this program; if not, write to the *
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "connecttoserverdialogimpl.h" #include "connecttoserverdialogimpl.h"
// #include "configfile.h" // #include "configfile.h"
#include <net/socket_msg.h> #include <net/socket_msg.h>
connectToServerDialogImpl::connectToServerDialogImpl(QWidget *parent) connectToServerDialogImpl::connectToServerDialogImpl(QWidget *parent)
: QDialog(parent) : QDialog(parent)
{ {
setupUi(this); setupUi(this);
} }
void connectToServerDialogImpl::refresh(int actionID) { void connectToServerDialogImpl::refresh(int actionID) {
switch (actionID) { switch (actionID) {
case MSG_SOCK_INIT_DONE: { label_actionMessage->setText("Resolving address..."); } case MSG_SOCK_INIT_DONE: { label_actionMessage->setText("Resolving address..."); }
break; break;
case MSG_SOCK_RESOLVE_DONE: { label_actionMessage->setText("Connecting to server..."); } case MSG_SOCK_RESOLVE_DONE: { label_actionMessage->setText("Connecting to server..."); }
break; break;
case MSG_SOCK_CONNECT_DONE: { label_actionMessage->setText("Starting session..."); } case MSG_SOCK_CONNECT_DONE: { label_actionMessage->setText("Starting session..."); }
break; break;
case MSG_SOCK_SESSION_DONE: { label_actionMessage->setText("Connection established!"); } case MSG_SOCK_SESSION_DONE: { label_actionMessage->setText("Connection established!"); }
break; break;
default: { label_actionMessage->setText("Please wait..."); } default: { label_actionMessage->setText("Please wait..."); }
} }
progressBar->setValue(actionID*(100/MSG_SOCK_LAST)); progressBar->setValue(actionID*(100/MSG_SOCK_LAST));
if (actionID == MSG_SOCK_LAST) if (actionID == MSG_SOCK_LAST)
QTimer::singleShot(1000, this, SLOT(accept())); QTimer::singleShot(1000, this, SLOT(accept()));
} }
void connectToServerDialogImpl::error(int errorID, int osErrorID) { void connectToServerDialogImpl::error(int errorID, int osErrorID) {
switch (errorID) { switch (errorID) {
case ERR_SOCK_SERVERADDR_NOT_SET: case ERR_SOCK_SERVERADDR_NOT_SET:
{QMessageBox::warning(this, tr("Network Error"), {QMessageBox::warning(this, tr("Network Error"),
tr("Server address was not set."), tr("Server address was not set."),
QMessageBox::Close); } QMessageBox::Close); }
break; break;
case ERR_SOCK_INVALID_PORT: case ERR_SOCK_INVALID_PORT:
{ QMessageBox::warning(this, tr("Network Error"), { QMessageBox::warning(this, tr("Network Error"),
tr("An invalid port was set (ports 0-1023 are not allowed)."), tr("An invalid port was set (ports 0-1023 are not allowed)."),
QMessageBox::Close); } QMessageBox::Close); }
break; break;
case ERR_SOCK_CREATION_FAILED: case ERR_SOCK_CREATION_FAILED:
{ QMessageBox::warning(this, tr("Network Error"), { QMessageBox::warning(this, tr("Network Error"),
tr("Could not create a socket for TCP communication."), tr("Could not create a socket for TCP communication."),
QMessageBox::Close); } QMessageBox::Close); }
break; break;
case ERR_SOCK_SET_PORT_FAILED: case ERR_SOCK_SET_PORT_FAILED:
{ QMessageBox::warning(this, tr("Network Error"), { QMessageBox::warning(this, tr("Network Error"),
tr("Could not set the port for this type of address."), tr("Could not set the port for this type of address."),
QMessageBox::Close); } QMessageBox::Close); }
break; break;
case ERR_SOCK_RESOLVE_FAILED: case ERR_SOCK_RESOLVE_FAILED:
{ QMessageBox::warning(this, tr("Network Error"), { QMessageBox::warning(this, tr("Network Error"),
tr("The server name could not be resolved."), tr("The server name could not be resolved."),
QMessageBox::Close); } QMessageBox::Close); }
break; break;
case ERR_SOCK_CONNECT_FAILED: case ERR_SOCK_CONNECT_FAILED:
{ QMessageBox::warning(this, tr("Network Error"), { QMessageBox::warning(this, tr("Network Error"),
tr("Could not connect to the server."), tr("Could not connect to the server."),
QMessageBox::Close); } QMessageBox::Close); }
break; break;
case ERR_SOCK_SELECT_FAILED: case ERR_SOCK_SELECT_FAILED:
{ QMessageBox::warning(this, tr("Network Error"), { QMessageBox::warning(this, tr("Network Error"),
tr("Internal network error: \"select\" failed."), tr("Internal network error: \"select\" failed."),
QMessageBox::Close); } QMessageBox::Close); }
break; break;
case ERR_SOCK_RECV_FAILED: case ERR_SOCK_RECV_FAILED:
{ QMessageBox::warning(this, tr("Network Error"), { QMessageBox::warning(this, tr("Network Error"),
tr("Internal network error: \"recv\" failed."), tr("Internal network error: \"recv\" failed."),
QMessageBox::Close); } QMessageBox::Close); }
break; break;
{ QMessageBox::warning(this, tr("Network Error"), { QMessageBox::warning(this, tr("Network Error"),
tr("Internal network error: \"send\" failed."), tr("Internal network error: \"send\" failed."),
QMessageBox::Close); } QMessageBox::Close); }
case ERR_SOCK_SEND_FAILED: case ERR_SOCK_SEND_FAILED:
break; break;
default: { QMessageBox::warning(this, tr("Network Error"), default: { QMessageBox::warning(this, tr("Network Error"),
tr("DEFAULT ERROR"), tr("DEFAULT ERROR"),
QMessageBox::Close); } QMessageBox::Close); }
} }
this->reject(); this->reject();
} }
+25 -25
View File
@@ -42,32 +42,32 @@ ServerThread::Main()
while (!ShouldTerminate()) while (!ShouldTerminate())
{ {
// Simple hacked server for testing. // Simple hacked server for testing.
SOCKET sockfd; SOCKET sockfd;
char buf[1024]; char buf[1024];
struct sockaddr_storage servaddr, clientaddr; struct sockaddr_storage servaddr, clientaddr;
int sockaddr_size = sizeof(struct sockaddr_in); int sockaddr_size = sizeof(struct sockaddr_in);
int addrFamily = AF_INET; int addrFamily = AF_INET;
int addrSize; socklen_t addrSize;
sockfd = socket(addrFamily, SOCK_STREAM, 0); sockfd = socket(addrFamily, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr)); bzero(&servaddr, sizeof(servaddr));
servaddr.ss_family = addrFamily; servaddr.ss_family = addrFamily;
socket_string_to_addr("0.0.0.0", addrFamily, (struct sockaddr *)&servaddr, sockaddr_size); socket_string_to_addr("0.0.0.0", addrFamily, (struct sockaddr *)&servaddr, sockaddr_size);
socket_set_port(7234, addrFamily, (struct sockaddr *)&servaddr, sockaddr_size); socket_set_port(7234, addrFamily, (struct sockaddr *)&servaddr, sockaddr_size);
bind(sockfd, (const struct sockaddr *)&servaddr, sockaddr_size); bind(sockfd, (const struct sockaddr *)&servaddr, sockaddr_size);
listen(sockfd, 1); listen(sockfd, 1);
bzero(&clientaddr, sizeof(clientaddr)); bzero(&clientaddr, sizeof(clientaddr));
addrSize = sockaddr_size; addrSize = sockaddr_size;
SOCKET conn = accept(sockfd, (struct sockaddr *)&clientaddr, &addrSize); SOCKET conn = accept(sockfd, (struct sockaddr *)&clientaddr, &addrSize);
CLOSESOCKET(sockfd); CLOSESOCKET(sockfd);
int ret = recv(conn, buf, sizeof(buf), 0); int ret = recv(conn, buf, sizeof(buf), 0);
send(conn, buf, ret, 0); send(conn, buf, ret, 0);
CLOSESOCKET(conn); CLOSESOCKET(conn);
} }
} }