Skip to content

Commit

Permalink
[protocol] just use UDP only
Browse files Browse the repository at this point in the history
  • Loading branch information
zhang-ray committed Dec 21, 2018
1 parent c07313c commit d8b7765
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 71 deletions.
13 changes: 0 additions & 13 deletions client_qt5/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ MainWindow::MainWindow(QWidget *parent)
onNetworkChanged(NetworkState::Disconnected);
toggleAdvancedMode(false);
showMessage("F1: help F2: toggle mode (advanced/easy mode)");
ui->radioButton_udp->toggle();
ui->radioButton_kcp_udp->setEnabled(false);
}


Expand Down Expand Up @@ -217,7 +215,6 @@ void MainWindow::onNetworkChanged(const NetworkState networkState){
if(mainThreadId_ == std::this_thread::get_id()){
switch(networkState){
case NetworkState::Disconnected: {
ui->groupBox_protocol->setEnabled(true);
ui->lineEdit_serverHost->setEnabled(true);
ui->lineEdit_serverPort->setEnabled(true);
ui->checkBox_needAec->setEnabled(true);
Expand All @@ -228,7 +225,6 @@ void MainWindow::onNetworkChanged(const NetworkState networkState){
break;
}
case NetworkState::Connecting: {
ui->groupBox_protocol->setEnabled(false);
ui->lineEdit_serverHost->setEnabled(false);
ui->lineEdit_serverPort->setEnabled(false);
ui->checkBox_needAec->setEnabled(false);
Expand All @@ -237,7 +233,6 @@ void MainWindow::onNetworkChanged(const NetworkState networkState){
break;
}
case NetworkState::Connected: {
ui->groupBox_protocol->setEnabled(false);
ui->lineEdit_serverHost->setEnabled(false);
ui->lineEdit_serverPort->setEnabled(false);
ui->checkBox_needAec->setEnabled(false);
Expand Down Expand Up @@ -305,15 +300,7 @@ void MainWindow::gotoWork(){
root_.put("server.host", ui->lineEdit_serverHost->text().toStdString().c_str());
root_.put("server.port", ui->lineEdit_serverPort->text().toStdString().c_str());

if (ui->radioButton_tcp->isChecked()) {
root_.put("protocol", "raw_tcp");
}
else if (ui->radioButton_udp->isChecked()) {
root_.put("protocol", "raw_udp");
}
else if (ui->radioButton_kcp_udp->isChecked()) {
root_.put("protocol", "kcp_udp");
}


worker_ = IWorker::create();
Expand Down
62 changes: 5 additions & 57 deletions client_qt5/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>600</width>
<height>460</height>
<height>339</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -359,7 +359,7 @@
<x>20</x>
<y>150</y>
<width>250</width>
<height>171</height>
<height>71</height>
</rect>
</property>
<property name="title">
Expand Down Expand Up @@ -388,64 +388,12 @@
<string>80</string>
</property>
</widget>
<widget class="QGroupBox" name="groupBox_protocol">
<property name="geometry">
<rect>
<x>10</x>
<y>54</y>
<width>231</width>
<height>111</height>
</rect>
</property>
<property name="title">
<string>protocol</string>
</property>
<widget class="QRadioButton" name="radioButton_tcp">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>111</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Raw TCP</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_kcp_udp">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>111</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>KCP/UDP</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_udp">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>111</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Raw UDP</string>
</property>
</widget>
</widget>
</widget>
<widget class="QPushButton" name="pushButton_connecting">
<property name="geometry">
<rect>
<x>20</x>
<y>340</y>
<y>250</y>
<width>250</width>
<height>61</height>
</rect>
Expand All @@ -471,7 +419,7 @@
<x>289</x>
<y>10</y>
<width>300</width>
<height>421</height>
<height>301</height>
</rect>
</property>
<property name="title">
Expand Down Expand Up @@ -541,7 +489,7 @@
<x>10</x>
<y>160</y>
<width>270</width>
<height>251</height>
<height>131</height>
</rect>
</property>
</widget>
Expand Down
50 changes: 49 additions & 1 deletion server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void printUsage() {



int main(int argc, char* argv[]) {
int main____(int argc, char* argv[]) {
std::shared_ptr<Server> server_ = nullptr;
try {
int port = 80;
Expand Down Expand Up @@ -73,4 +73,52 @@ int main(int argc, char* argv[]) {
}

return 0;
}


int main(int argc, char* argv[]) {
std::shared_ptr<Server> server_ = nullptr;
try {
int port = 80;

if ((argc != 2)&&(argc != 3)) {
printUsage();
return -1;
}


if (argc == 3) {
if (!strcmp("broadcast", argv[2])) {
isEchoMode = false;
}
else if (!strcmp("echo", argv[2])) {
isEchoMode = true;
}
else {
printUsage();
return -1;
}
}


port = std::atoi(argv[1]);


LOGI << "PORT=" << port;
if (isEchoMode ) LOGI<< "ECHO MODE";

boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::trace);

boost::asio::io_service io_service;

server_ = std::make_shared<RawUdpServer>(io_service, port);


io_service.run();
}
catch (std::exception& e) {
std::cerr << "Exception: " << e.what() << "\n";
}

return 0;
}

0 comments on commit d8b7765

Please sign in to comment.