chat::chat(QString pasvusername, QString pasvuserip) : ui(new Ui::chat) { ui->setupUi(this); ui->textEdit->setFocusPolicy(Qt::StrongFocus); ui->textBrowser->setFocusPolicy(Qt::NoFocus); ui->textEdit->setFocus(); ui->textEdit->installEventFilter(this); a = 0; is_opened = false; // this->is_opened = false; xpasvusername = pasvusername; xpasvuserip = pasvuserip; ui->label->setText(tr("与%1聊天中 对方IP:%2").arg(xpasvusername).arg(pasvuserip)); //UDP部分 xchat = new QUdpSocket(this); xport = 45456; // xchat->bind(xport, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); xchat->bind( QHostAddress(getIP()), xport ); connect(xchat, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); //TCP部分 server = new TcpServer(this); connect(server,SIGNAL(sendFileName(QString)),this,SLOT(sentFileName(QString))); connect(ui->textEdit,SIGNAL(currentCharFormatChanged(QTextCharFormat)),this,SLOT(currentFormatChanged(const QTextCharFormat))); }
void MainWindow::initSocket() { //socket creation udpSocket = new QUdpSocket(this); alreadySocket = new QUdpSocket(this); dataSocket = new QUdpSocket(this); //if there is 2 arguments if(QCoreApplication::arguments().length()==2) { //save argument 1 (buildDir) QString newarg = QCoreApplication::arguments().at(1); //convert argument const char *newData=newarg.toStdString().c_str(); //send buildDir to pandarduino dataSocket->writeDatagram(newData, strlen(newData)+1,QHostAddress::LocalHost, 45454); } //socket binding udpSocket->bind(45454, QUdpSocket::ShareAddress); //connect socket and pending datagrams slot connect(udpSocket, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams())); }
Receiver::Receiver(QWidget *parent) : QDialog(parent) { qDebug() << "Start receiving: "; int host; host = QInputDialog::getInt(0,"Port","Insert port"); statusLabel = new QLabel(tr("Listening for broadcasted messages")); quitButton = new QPushButton(tr("&Quit")); udpSocket = new QUdpSocket(this); udpSocket->bind(host, QUdpSocket::ShareAddress); connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(1); buttonLayout->addWidget(quitButton); buttonLayout->addStretch(1); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(statusLabel); mainLayout->addLayout(buttonLayout); setLayout(mainLayout); setWindowTitle(tr("Broadcast Receiver")); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { //setup some default values in the constructor //Direction commands from remote -- (text label, number of pulses, x movement, y movement) pulseDecode.append(DirectionCommand("UP", 10, 0, -0.5)); pulseDecode.append(DirectionCommand("DOWN", 40, 0, 1)); pulseDecode.append(DirectionCommand("LEFT", 58, -1, 0)); pulseDecode.append(DirectionCommand("RIGHT", 64, 1, 0)); pulseDecode.append(DirectionCommand("DOWN + LEFT", 52, -0.707, 0.707)); pulseDecode.append(DirectionCommand("UP + LEFT", 28, -0.707, -0.707)); pulseDecode.append(DirectionCommand("DOWN + RIGHT", 46, 0.707, 0.707)); pulseDecode.append(DirectionCommand("UP + RIGHT", 34, 0.707, -0.707)); //initialize other variables currentType = NONE; elementCounter = 0; pulseCounter = 0; pixelRatio = 3.0; v1 = 0; v2 = 0; //initialize UI components ui->setupUi(this); //set up TCP client and connect to GNU Radio server (note: start GNURadio before program) tcpSocket.abort(); tcpSocket.connectToHost("127.0.0.1",2600); connect(&tcpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); }
chat::chat(QString pasvusername,QString pasvuserip): ui(new Ui::chat) { ui->setupUi(this); ui->textEdit->setFocusPolicy(Qt::StrongFocus); ui->textBrowser->setFocusPolicy(Qt::NoFocus); ui->textEdit->setFocus(); ui->textEdit->installEventFilter(this); ui->send->setStyleSheet(tr("QPushButton{ border:0px;border-radius:5px;color:white;background-color:rgb(172, 213, 191)}QPushButton:hover{background-color:rgb(153, 186, 255);}QPushButton:pressed{background-color:rgb(153, 186, 255);}")); //退出按钮 ui->close->setStyleSheet(tr("QPushButton{border:0px;border-radius:5px;color:white;background-color:rgb(195, 195, 195);}QPushButton:hover{background-color:#505050;}QPushButton:pressed{background-color:#505050;}")); a = 0; is_opened = false; // this->is_opened = false; xpasvusername = pasvusername; xpasvuserip = pasvuserip; ui->label->setText(tr("与%1聊天中 对方IP:%2").arg(xpasvusername).arg(pasvuserip)); //UDP部分 xchat = new QUdpSocket(this); xport=6900; // xchat->bind(xport, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); QHostAddress chat_me(getIP()); xchat->bind( chat_me, xport); connect(xchat, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); //TCP部分 server = new TcpSend(this); connect(server,SIGNAL(sendFileName(QString)),this,SLOT(sentFileName(QString))); connect(ui->textEdit,SIGNAL(currentCharFormatChanged(QTextCharFormat)),this,SLOT(currentFormatChanged(const QTextCharFormat))); }
Receiver::Receiver(QWidget *parent) : QDialog(parent) { groupAddress = QHostAddress("239.255.43.21"); statusLabel = new QLabel(tr("Listening for multicasted messages")); quitButton = new QPushButton(tr("&Quit")); udpSocket = new QUdpSocket(this); udpSocket->bind(45454, QUdpSocket::ShareAddress); udpSocket->joinMulticastGroup(groupAddress); connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(1); buttonLayout->addWidget(quitButton); buttonLayout->addStretch(1); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(statusLabel); mainLayout->addLayout(buttonLayout); setLayout(mainLayout); setWindowTitle(tr("Multicast Receiver")); }
UdpEchoServer::UdpEchoServer() : m_pUdpSocket(new QUdpSocket(this)), m_port(2011) { connect(m_pUdpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); }
NetworkWidget::NetworkWidget(QWidget *parent, AbstractSerial *serial) : QWidget(parent), serial(serial), ui(new Ui::NetworkWidget) { ui->setupUi(this); udpSocket = new QUdpSocket(this); connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); if ( udpSocket->localAddress().isNull() ) { ui->lblIP_address->setText("0.0.0.0"); } else { ui->lblIP_address->setText( udpSocket->localAddress().toString() ); } QLineEdit *temp[] = { ui->PWM_01, ui->PWM_02, ui->PWM_03, ui->PWM_04, ui->PWM_05, ui->PWM_06, ui->PWM_07, ui->PWM_08, ui->PWM_09, ui->PWM_10, ui->PWM_11, ui->PWM_12 }; for (unsigned char i=0; i<(sizeof(temp)/sizeof(temp[0])); i++) currentServoValue[i] = temp[i]; // Zero out all the stats. stats_packets = stats_invalid = stats_queue_max = stats_discarded = stats_packets_old = stats_network_failures = 0; ui->lblStatus->setText(tr("Not Listening")); socketOpen = false; STATE = NOT_LISTENING; emptyQueue(); ui->btnClearEmergencyStop->setDisabled(true); OutputTimer = new QTimer(this); NetworkTimer = new QTimer(this); connect(OutputTimer, SIGNAL(timeout()), this, SLOT(ouputServoData())); connect(NetworkTimer, SIGNAL(timeout()), this, SLOT(checkNetwork())); }
/*! * Standard constructor using \a parent as parent */ LogReceiver::LogReceiver(QObject *parent) : QObject(parent), m_socket(new QUdpSocket(this)) { setPort(45454); connect(m_socket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); }
Receiver::Receiver(QWidget *parent) : QDialog(parent) { statusLabel = new QLabel(tr("Listening for broadcasted messages")); quitButton = new QPushButton(tr("&Quit")); //! [0] udpSocket = new QUdpSocket(this); udpSocket->bind(45454, QUdpSocket::ShareAddress); //! [0] //! [1] connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); //! [1] connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(1); buttonLayout->addWidget(quitButton); buttonLayout->addStretch(1); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(statusLabel); mainLayout->addLayout(buttonLayout); setLayout(mainLayout); setWindowTitle(tr("Broadcast Receiver")); }
bool ICServer::startSidTest(int duration) { timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(stopSidTest())); timer->setInterval(duration); timer->setSingleShot(true); testUdpSocket = new QUdpSocket(this); bool success = testUdpSocket->bind(ipAddress, CLIENT_PORT); // if bind failed if (!success) return false; connect(testUdpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); ICMessage question = ICMessage::initWithCommonProperties(); question.setProperty(settings->value(SID_CONFIG_TAG,DEFAULT_SID_TAG).toString(),sid); question.setProperty(settings->value(COMMAND_CONFIG_TAG,DEFAULT_CMD_TAG).toString(), QString::number(SERVER_DISCOVERY)); // broadcast for three times for (int i = 0; i < 3; i++) testUdpSocket->writeDatagram(question.saveAsJson(), QHostAddress::Broadcast, SERVER_PORT); timer->start(); return true; }
YAQSProxy::YAQSProxy(QObject *parent) : QObject(parent) { timer.setInterval(msTimerResolution); timer.start(); udpSocket.bind(portNumber, QUdpSocket::ShareAddress); connect(&timer, SIGNAL(timeout()), this, SLOT(broadcast())); connect(&udpSocket, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams())); }
NetworkMonitor::NetworkMonitor( int listenPort, int sendPort ) { this->listenPort = listenPort; this->sendPort = sendPort; connect( &socket, SIGNAL(readyRead()), this, SLOT( processPendingDatagrams() ) ); connect( &pingTimer, SIGNAL( timeout() ), this, SLOT( sendPing() ) ); createPing( ); }
void udpreceiver::startreceiver() { udpSocket = new QUdpSocket(this); udpSocket->bind(45454, QUdpSocket::ShareAddress); connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); // qDebug()<< "UDP CONNECETED"; }
UAV::UAV(QWidget *parent) // : QDialog(parent) { udpSocket.bind(27015); connect(&udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); // QTextStream(stdout) << "run this shit"; }
server::server(QString host, quint16 p) { udpSocket.bind(QHostAddress(host),p); connect(&udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); qDebug() << "Server started ::: " << udpSocket.localAddress() << udpSocket.localPort(); }
/*********************************************************************** * 函数名称: listen * 函数功能: 监听事件 * 参数说明: * 作者 : 爱在梦幻谷 * 最后修改: 2013年3月14日21:00:52 ***********************************************************************/ bool login::listen() { if(!m_pTestLinkSocket->bind(LOGIN_LISTEN_PORT)) { qDebug() << __FILE__ <<":"<< __LINE__ <<" p_ListenUdpSoket->bind fail!"; return false; } connect(m_pTestLinkSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams()), Qt::DirectConnection); return true; }
// listen on port 8027, broadcast question to 8026 bool ICServer::listen() { udpSocket = new QUdpSocket(this); if (udpSocket->bind(ipAddress, SERVER_PORT)) { connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); //connect(udpSocket,SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(socketClosed(QAbstractSocket::SocketError))); isRunning = true; return true; } else return false; }
/** * \brief wavrUdpNetwork::stop * Disconnects the readyRead signal, leaves multicast group, and closes the socket connection. */ void wavrUdpNetwork::stop(void) { disconnect(pUdpReceiver, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); if(pUdpReceiver->state() == QAbstractSocket::BoundState) { wavrTrace::write("Leaving multicast group " + multicastAddress.toString() + " on interface " + multicastInterface.humanReadableName()); bool left = pUdpReceiver->leaveMulticastGroup(multicastAddress, multicastInterface); pUdpReceiver->close(); wavrTrace::write(left ? "Success" : "Failed"); } isRunning = false; }
/*!\func TCore * конструктор класса * \param нет * \return нет */ TCore::TCore(const QString &newPluginsDir, quint16 localPort) : address(QHostAddress::Broadcast), timer() { // qDebug()<<"TCore"; this->pluginsDir = newPluginsDir; //уникальный типа ИД unique_id = 1; connect(&timer, SIGNAL(timeout()), this, SLOT(on_timer())); timer.start(1000); //создаем соккет this->localPort = localPort; remoutePort = 45454; udpSocket.bind(localPort); connect(&udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); }
UDPReceiver::UDPReceiver() { setObjectName(metaObject()->className()); addOutputPort("OUT"); setSelfStarting(true); udpSocket = new QUdpSocket(); udpSocket->bind(4444, QUdpSocket::ShareAddress); bool check = connect(udpSocket, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams())); Q_ASSERT(check); }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); //QHostInfo::lookupHost("www.baidu.com", this, SLOT(lookedup(QHostInfo))); //获取网络地址 udpSocket = new QUdpSocket(this); port = 55555; udpSocket->bind(port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); sendMessage(NewParticipant); }
Client::Client(QWidget *parent) : QDialog(parent) { groupAddress = QHostAddress("230.0.0.1"); port = 7777; strcpy(mess.id, "Cristina\0"); listRooms.push_back(string("room1\0")); listRooms.push_back(string("room2\0")); listRooms.push_back(string("room3\0")); listRooms.push_back(string("name\0")); okButton = new QPushButton(tr("&Ok")); cancelButton = new QPushButton(tr("&Clear")); ttlLabel = new QLabel(tr("TTL for multicast datagrams:")); ttlSpinBox = new QSpinBox; ttlSpinBox->setRange(0, 255); QHBoxLayout *ttlLayout = new QHBoxLayout; ttlLayout->addWidget(ttlLabel); ttlLayout->addWidget(ttlSpinBox); buttonBox = new QDialogButtonBox; buttonBox->addButton(okButton, QDialogButtonBox::ActionRole); buttonBox->addButton(cancelButton, QDialogButtonBox::ActionRole); waitList = false; udpSocket = new QUdpSocket(this); udpSocket->bind(port, QUdpSocket::ShareAddress); udpSocket->joinMulticastGroup(groupAddress); connect(ttlSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ttlChanged(int))); connect(okButton,SIGNAL(clicked()), this, SLOT(sendDatagram())); connect(udpSocket, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams())); connect(cancelButton, SIGNAL(clicked()), this, SLOT(eraseInput())); QVBoxLayout *mainLayout = new QVBoxLayout; outputText = new QTextBrowser; inputText = new QTextEdit; inputText->setFixedHeight(1*30); mainLayout->addLayout(ttlLayout); mainLayout->addWidget(outputText); mainLayout->addWidget(inputText); mainLayout->addWidget(buttonBox); setLayout(mainLayout); setWindowTitle(tr("Multicast")); ttlSpinBox->setValue(1); }
Widget::Widget(qint16 selfport,qint16 destinationport,QString destinationIP,QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { //initialize all the variable ui->setupUi(this); udpSocket=new QUdpSocket(); port=selfport; destport=destinationport; destIP=destinationIP; this->setWindowTitle("My port is "+QString::number(port)); connect(udpSocket,SIGNAL(readyRead()),this,SLOT(processPendingDatagrams())); }
int CIMServer::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: processPendingDatagrams(); break; case 1: DisplayError((*reinterpret_cast< QAbstractSocket::SocketError(*)>(_a[1]))); break; default: ; } _id -= 2; } return _id; }
/** * Joins the multicast group and listens for incoming packets. */ bool wavrUdpNetwork::startReceiving(void) { wavrTrace::write("Binding UDP listener to port " + QString::number(nUdpPort)); if(pUdpReceiver->bind(QHostAddress::AnyIPv4, nUdpPort)) { wavrTrace::write("Success"); wavrTrace::write("Joining multicast group " + multicastAddress.toString() + " on interface " + multicastInterface.humanReadableName()); bool joined = pUdpReceiver->joinMulticastGroup(multicastAddress, multicastInterface); wavrTrace::write((joined ? "Success" : "Failed")); connect(pUdpReceiver, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); return true; } wavrTrace::write("Failed"); return false; }
AmptekSDD123Server::AmptekSDD123Server(AmptekSDD123ConfigurationMap *configurationMap, const QString &serverName, QObject *parent) : QObject(parent) , currentRequestPacket_(-1, QString("NONE")), currentSyncPacket_(-1, QString("NONE")), timedOutPacket_(-1, QString("NONE")) { spectrumPacketReceiver_ = 0; confirmationPacketReceiver_ = 0; configurationMap_ = configurationMap; serverName_ = serverName; requestIntervalTimer_ = -1; totalResponseDatagramSize_ = 0; currentlyReadSize_ = 0; amptekHeaderBytes_ = QByteArray::fromHex("f5fa"); if(configurationMap_){ stillReceivingResponseDatagram_ = false; socketLocallyBusy_ = false; detectorUnavailable_ = false; currentRequestTime_.start(); requestPacketTimer_ = new QTimer(this); requestPacketTimer_->setSingleShot(true); syncPacketTimer_ = new QTimer(this); syncPacketTimer_->setSingleShot(true); packetIDCounter_ = 27; hasReplyReady_ = false; timeOutIDCounter_ = -27; requestSpectrumTime_ = new QTime(); requestSpectrumTime_->start(); lastRequestSpectrumTime_ = new QTime(); lastRequestSpectrumTime_->start(); replySpectrumTime_ = new QTime(); replySpectrumTime_->start(); udpDetectorSocket_ = new QUdpSocket(this); bool boundUDP = udpDetectorSocket_->bind(configurationMap_->localAddress(), 10001, QUdpSocket::ShareAddress); if (!boundUDP) AMDSRunTimeSupport::debugMessage(AMDSRunTimeSupport::AlertMsg, this, AMPTEK_SERVER_ALERT_FAILED_TO_BOUND_UDP, QString("Amptek Server failed to bound to the detector via %1:%2").arg(configurationMap_->localAddress().toString()).arg(10001)); connect(udpDetectorSocket_, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); connect(this, SIGNAL(responsePacketReady()), this, SLOT(onResponsePacketReady())); } }
MQTT::MQTT(QObject *parent) : QObject(parent) { // re-initialize connection whenever the // host or the port changes QObject::connect(this, SIGNAL(hostChanged(QString)), this, SLOT(initializeConnection())); QObject::connect(this, SIGNAL(portChanged(int)), this, SLOT(initializeConnection())); qDebug()<<"Rahr: testing"; numberOfData =0; udpSocket = new QUdpSocket(this); udpSocket->bind(3000, QUdpSocket::ShareAddress); QObject::connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); }
MapController::MapController(Map* inputMap, QObject* parent) : QObject(parent), map(inputMap), buddiesLayerVisible(true), observationsLayerVisible(true), udpSocket(NULL), broadcastPort(45678), broadcastInterval(3000), simulator(), positionReportTimer(NULL), acceptPositionReports(true), acceptSpotReports(true), appConfigDialog(NULL), showOwnship(false), followOwnship(false), isMapReady(false), drawingOverlay(0), lastHeading(0.0), mouseState(MouseStateNone) { if (QFile::exists("./route.gpx")) simulator.setGpxFile("./route.gpx"); else simulator.setGpxFile(GPS_SIMULATION_FILE); simulator.setTimerInterval(40); // Warning: jumpy at some intervals (ex. 100) simulator.setPlaybackMultiplier(25); connect(&simulator, SIGNAL(positionUpdateAvailable(QPointF, double)), this, SLOT(handlePositionAvailable(QPointF, double))); readAppConfig(); // create the messaging socket connection and hook up message receiving udpSocket = new QUdpSocket(this); udpSocket->bind(broadcastPort, QUdpSocket::DontShareAddress | QUdpSocket::ReuseAddressHint); connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); //Timer to send the position report positionReportTimer = new QTimer(this); positionReportTimer->setInterval(1000); connect(positionReportTimer, SIGNAL(timeout()), this, SLOT(sendPositionMessage())); handleToggleBroadcastPosition(true); handleToggleShowMe(true); handleToggleFollowMe(true); chemLightColorStr = "None"; }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); udpSocket = new QUdpSocket(this); port = 45454; udpSocket->bind(port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams())); sendMessage(NewParticipant); server = new TcpServer(this); connect(server, SIGNAL(sendFileName(QString)), this, SLOT(getFileName(QString))); connect(ui->messageTextEdit, SIGNAL(currentCharFormatChanged(QTextCharFormat)), this, SLOT(currentFormatChanged(const QTextCharFormat))); }