int main() { char google[] = "173.194.79.103"; char message[] = "GET / HTTP/1.1\r\n\r\n"; char reply[2000]; int port = 80; int ret, sd; sd = socketCreate(); printf("Created socket wrapper with descriptor %d.\n", sd); ret = socketConnect(sd, google, port); printf("Socket wrapper connected to '%s' on port '%d' with return value %d.\n", google, port, ret); ret = socketSend(sd, message, -1); printf("Socket wrapper sent: \n\n'%s'\n\nto '%s' on port '%d' with return value %d.\n", message, google, port, ret); ret = socketReceive(sd, reply, 2000); printf("Socket wrapper received: \n\n'%s'\n\nfrom '%s' on port '%d' with return value %d.\n", reply, google, port, ret); ret = socketDisconnect(sd); printf("Socket wrapper disconnected from '%s' on port '%d' with return value %d.\n", google, port, ret); return 0; }
void EthernetServer::accept() { bool listening = false; if (sockindex < MAX_SOCK_NUM) { uint8_t status = socketStatus(sockindex); if (status == SnSR::LISTEN) { listening = true; } else if (status == SnSR::CLOSE_WAIT && socketRecvAvailable(sockindex) <= 0) { socketDisconnect(sockindex); } } if (!listening) begin(); }
static jboolean com_android_nfc_NativeP2pDevice_doDisconnect(JNIEnv *e, jobject o) { uint32_t handle = nfc_jni_get_nfc_socket_handle(e, o); bool_t canUse = W_FALSE; jclass target_cls = NULL; jfieldID f; if(IS_SERVER_SOCKET(handle)) { return serverSocketDisconnect(handle); } else if(IS_CLIENT_SOCKET(handle)) { return socketDisconnect(handle); } return JNI_FALSE; }
void AdminServerTask::run() { QTcpSocket tcpSocket; if (!tcpSocket.setSocketDescriptor(taskSocketDescriptor)) { QLogger(QLogger::INFO_SYSTEM, QLogger::LEVEL_ERROR) << __FUNCTION__ << "Error converting socket descriptor to socket:" << tcpSocket.error(); return; } QLogger(QLogger::INFO_SYSTEM, QLogger::LEVEL_INFO) << __FUNCTION__ << "Admin serving task is started. Agent ip:" << tcpSocket.peerAddress().toString() << ":" << tcpSocket.peerPort(); commandExecutor = new AdminCommandExecutor(); Q_ASSERT(commandExecutor != NULL); // Read and parse commands from socket packetsReadLoop(&tcpSocket); delete commandExecutor; commandExecutor = NULL; // Ending connection socketDisconnect(&tcpSocket); }
MainWindow::MainWindow(QString filename, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); setWindowTitle(QApplication::applicationName()+" "+ QApplication::applicationVersion()); //ui->lastValuesBox->hide(); bytesRead=0; bytesWritten=0; lastValueDoubleClick=new DoubleClickEventFilter(this); ui->lastValuesBox->installEventFilter(lastValueDoubleClick); connect (lastValueDoubleClick,SIGNAL(doubleClicked()),this,SLOT(clearLastValues())); connect (lastValueDoubleClick,SIGNAL(doubleClicked()),this,SLOT(initLastValues())); appSettings=new QSettings(QSettings::IniFormat,QSettings::UserScope,QApplication::organizationName(),QApplication::applicationName(),this); data=new ExperimentData(this); dilatometerData=new DilatometerData(this); data->setDilatometerData(dilatometerData); experiment=new Experiment(&tcpClient,this); dilatometerPlot=NULL; plot=new Plot(this); plot->setExperimentData(data); plot->setAxisTitle(QwtPlot::xBottom,tr("t, sec")); ui->plotLayout->addWidget(plot); connect(ui->actionFullscreen,SIGNAL(triggered(bool)),this,SLOT(setFullscreen(bool))); connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(close())); connect(ui->actionConnect_to,SIGNAL(triggered()),this,SLOT(connectTo())); connect(ui->actionDisconnect,SIGNAL(triggered()),this,SLOT(socketDisconnect())); connect(ui->actionViewData,SIGNAL(triggered()),this,SLOT(showDataViewWindow())); connect(ui->actionReplot,SIGNAL(triggered()),plot,SLOT(replot())); connect(ui->actionClear_plot,SIGNAL(triggered()),plot,SLOT(clear())); connect(ui->actionInitialize,SIGNAL(triggered()),plot,SLOT(initialize())); connect(ui->actionSelect_points,SIGNAL(toggled(bool)),plot,SLOT(selectPointsMode(bool))); connect(ui->actionZoom_to_extents,SIGNAL(triggered()),plot,SLOT(zoomExtents())); connect(ui->actionDraw_incremental,SIGNAL(triggered(bool)),plot,SLOT(setIncrementalDraw(bool))); connect(ui->actionOpen_file,SIGNAL(triggered()),SLOT(openFile())); connect(ui->actionSave_as,SIGNAL(triggered()),SLOT(saveFile())); connect(ui->actionMonitoring_interval,SIGNAL(triggered()),SLOT(setMonitoringInterval())); connect(ui->actionSetup,SIGNAL(triggered()),SLOT(showSetupCurvesDialog())); connect(ui->actionSet_interval,SIGNAL(triggered()),SLOT(setInterval())); connect(ui->actionControl,SIGNAL(triggered()),SLOT(viewExperimentControlDialog())); connect(ui->actionStart,SIGNAL(triggered(bool)),&tcpClient,SLOT(start(bool))); connect(ui->actionApproximate,SIGNAL(triggered()),SLOT(approximate())); connect(ui->actionShow_approximations,SIGNAL(triggered(bool)),plot,SLOT(showApproximationCurves(bool))); connect(ui->actionConfiguration,SIGNAL(triggered()),SLOT(showConfigurationDialog())); connect(ui->actionLast_calculation,SIGNAL(triggered()),SLOT(showCalculationLog())); connect(ui->actionDilatometry,SIGNAL(toggled(bool)),SLOT(showDilatometryPlot(bool))); connect(ui->actionZoom_yLeft_to_extents,SIGNAL(triggered()),SLOT(zoomYLeftToExtents())); connect(ui->actionAbout_Qt,SIGNAL(triggered()),QApplication::instance(),SLOT(aboutQt())); connect(ui->actionAbout,SIGNAL(triggered()),SLOT(showAbout())); connect(ui->actionSet_tolerance_alarm,SIGNAL(triggered()),plot,SLOT(setToleranceAlarm())); connect(ui->actionRemove_tolerance_alarm,SIGNAL(triggered()),plot,SLOT(removeToleranceAlarm())); connect(ui->actionView_tolerance,SIGNAL(triggered()),SLOT(showToleranceAlarmState())); plot->enableAutoZoom(ui->actionAuto_zoom->isChecked()); connect(ui->actionAuto_zoom,SIGNAL(triggered(bool)),plot,SLOT(enableAutoZoom(bool))); //ui->actionDraw_incremental->trigger(); connect(plot,SIGNAL(message(QString)),statusBar(),SLOT(showMessage(QString))); connect(ui->actionSelectT0,SIGNAL(toggled(bool)),plot,SLOT(selectT0(bool))); connect(plot,SIGNAL(T0Selected(bool)),ui->actionSelectT0,SLOT(trigger())); connect(plot,SIGNAL(T0Selected(bool)),ui->actionSelect_points,SLOT(setChecked(bool))); connect(plot,SIGNAL(toleranceAlarmSet(bool)),SLOT(toleranceAlarmStatusChange(bool))); connect(plot,SIGNAL(curvePointClicked(QwtPlotCurve*,int)),this,SLOT(updateSelectedValue(QwtPlotCurve*,int))); connect(&tcpClient,SIGNAL(connected()),this,SLOT(socketConnectedToServer())); connect(&tcpClient,SIGNAL(disconnected()),this,SLOT(socketDisconnectedFromServer())); connect(&tcpClient,SIGNAL(stateChanged(QAbstractSocket::SocketState)),this,SLOT(socketStateChanged(QAbstractSocket::SocketState))); connect(&tcpClient,SIGNAL(dataLine(QByteArray&)),data,SLOT(parseLine(QByteArray&))); connect(&tcpClient,SIGNAL(initialData()),plot,SLOT(clear())); connect(&tcpClient,SIGNAL(initialData()),data,SLOT(resetData())); connect(&tcpClient,SIGNAL(serverStatus(bool)),ui->actionStart,SLOT(setChecked(bool))); connect(&tcpClient,SIGNAL(bytesWritten(int)),this,SLOT(appendBytesWritten(int))); connect(&tcpClient,SIGNAL(bytesRead(int)),this,SLOT(appendBytesRead(int))); connect(&tcpClient,SIGNAL(serverInterval(int)),experiment,SLOT(setInterval(int))); connect(data,SIGNAL(initialized()),plot,SLOT(initialize())); connect(data,SIGNAL(initialized()),this,SLOT(initLastValues())); connect(data,SIGNAL(pointCount(int)),&pointCountLabel,SLOT(setNum(int))); connect(data,SIGNAL(pointCount(int)),plot,SLOT(drawLastPoint())); /** This connection will cause to plot VLine markers*/ //connect(data,SIGNAL(marker(QPointF,int)),plot,SLOT(appendMarker(QPointF,int))); connect(data,SIGNAL(marker(int)),plot,SLOT(appendMarker(int))); connect(data,SIGNAL(pointCount(int)),this,SLOT(updateLastValues())); connect(data,SIGNAL(heaterPower(int)),this,SLOT(setHeaterPower(int))); connectionLabel.setText("*"); connectionLabel.setToolTip(tr("Connection status:\nGreen - connected\nRed - disconnected")); connectionLabel.setStyleSheet("QLabel {color:red; font-weight:bold;}"); pointCountLabel.setText("0"); pointCountLabel.setToolTip(tr("Number of points")); bytesWrittenLabel.setText("0"); bytesWrittenLabel.setToolTip("Bytes written to network"); bytesReadLabel.setText("0"); bytesReadLabel.setToolTip("Bytes read from network"); ui->heaterPowerBar->setStyleSheet("QProgressBar::chunk {margin: 0px; width: 1px;}"); ui->statusBar->addPermanentWidget(&bytesReadLabel); ui->statusBar->addPermanentWidget(&bytesWrittenLabel); ui->statusBar->addPermanentWidget(&pointCountLabel); ui->statusBar->addPermanentWidget(&connectionLabel); //if file was specified on startup - try open it if (!filename.isEmpty()) openFile(filename); }
// called by the socket when disconnected void TcpConnector::sDisconnect() { logMessage("disconneted"); emit socketDisconnect(); }