示例#1
0
int main()
{
  int portFD = open("/dev/i2c-1", O_RDWR);
  i2c_port myPort(portFD, 0);
  i2c_rdwr_ioctl_data transactions;
  i2c_msg messages[2];
  printf("%d\r\n", portFD);
  unsigned short mpr121Address = 0x005a;
  unsigned char regAddr = 0x5d;
  unsigned char *dBuf;
  messages[0].len = 1;
  messages[0].flags = 0;
  messages[0].addr = mpr121Address;
  messages[0].buf = &regAddr;

  messages[1].addr = mpr121Address;
  messages[1].flags = I2C_M_RD;
  messages[1].len = 1;
  messages[1].buf = dBuf; 
  
  transactions.nmsgs = 2;
  transactions.msgs = messages;

  myPort.transferPackets(&transactions);
  printf("%x\n\r", dBuf);

} 
示例#2
0
void
MessageWindow::DCCServerSetup (void)
{
  int32 myPort (1500 + (rand() % 5000));
  struct sockaddr_in sa;
	
  mySocket = socket (AF_INET, SOCK_STREAM, 0);

  if (mySocket < 0)
  {
    Display ("Error creating socket.\n", 0);
    return;
  }

  BLooper *looper;
  ServerWindow *server;
  sMsgr.Target (&looper);
  server = dynamic_cast<ServerWindow *>(looper);

  sa.sin_family = AF_INET;
  sa.sin_addr.s_addr = server->LocaluIP();
  sa.sin_port = htons(myPort);
  if (bind (mySocket, (struct sockaddr*)&sa, sizeof(sa)) == -1)
  {
    myPort = 1500 + (rand() % 5000); // try once more
    sa.sin_port = htons(myPort);
    if (bind (mySocket, (struct sockaddr*)&sa, sizeof(sa)) == -1)
    {
      Display ("Error binding socket.\n", 0);
      return;
    }
  }

  BMessage msg (M_SERVER_SEND);
  BString buffer;

  buffer << "PRIVMSG " << chatee << " :\1DCC CHAT chat ";
  buffer << htonl (server->LocaluIP()) << " ";
  buffer << myPort << "\1";
  msg.AddString ("data", buffer.String());
  sMsgr.SendMessage (&msg);
	
  listen (mySocket, 1);

  {
    BMessage msg (M_DISPLAY);
    BString buffer;
    struct in_addr addr;
		
    addr.s_addr = server->LocaluIP();
    buffer << "Accepting connection on address "
      << inet_ntoa (addr) << ", port " << myPort << "\n";

    Display (buffer.String(), 0);
  }
}
示例#3
0
/** 
 * This example is made to show you how you can use the Options.
 */
int main(int, char **)
{
	try
	{
		curlpp::Cleanup myCleanup;

		// First easy example.
		{
		  // The first easiest example is to retreive the content of
		  // a web page and put it in a stream.
		  std::cout << curlpp::options::Url("http://example.com");

		  // You don't need to use just the standard outputs. You
		  // can use any stream:
		  std::ostringstream os;
		  os << curlpp::options::Url("http://example.com");
		}

		// More elaborate example.
		{
		  // What the previous example done there was simply 
		  // to create a curlpp::Easy class, which is the basic
		  // object in cURLpp, and then set the Url option.
		  // curlpp::options classes are the primitives that allow to specify 
		  // values to the requests. 
		  curlpp::options::Url myUrl(std::string("http://example.com"));
		  curlpp::Easy myRequest;
		  myRequest.setOpt(myUrl);

		  // Now that all the options we wanted to set are there, we need to
		  // actually do the request. the "perform" method does actually that.
		  // With that call, the request will be done and the content of that URL
		  // will be printed in std::cout (which is the default).
		  myRequest.perform();

		  // If we wanted to put the content of the URL within a string stream
		  // (or any type of std::ostream, for that matter), like the first example, 
		  // we would use the WriteStrem option like this:
		  std::ostringstream os;
		  curlpp::options::WriteStream ws(&os);
		  myRequest.setOpt(ws);
		  myRequest.perform();

		  // There is some shorcut within curlpp that allow you to write shorter code
		  // like this:
		  os << myRequest;

		  // That would do exactly what the previous code was doing.
		}

		// Creation of the URL option.
		curlpp::options::Url myUrl(std::string("http://example.com"));

		// Copy construct from the other URL.
		curlpp::options::Url myUrl2(myUrl);

		// Creation of the port option.
		curlpp::options::Port myPort(MyPort);

		// Creation of the request.
		curlpp::Easy myRequest;

		// Creation of an option that contain a copy of the URL option.
		curlpp::OptionBase *mytest = myUrl.clone();
		myRequest.setOpt(*mytest);

		// You can reuse the base option for other type of option
		// and set the option to the request. but first, don't forget 
		// to delete the previous memory. You can delete it since the 
		// option is internally duplicated for the request.
		delete mytest;
		mytest = myPort.clone();
		myRequest.setOpt(*mytest);
		delete mytest;

		// You can clone an option directly to the same type of 
		// option.
		curlpp::options::Url *myUrl3 = myUrl.clone();
		myRequest.setOpt(myUrl3);
		// Now myUrl3 is owned by the request we will NOT use 
		// it anymore.


		// You don't need to declare an option if you just want 
		// to use it once.
		myRequest.setOpt(curlpp::options::Url("example.com"));


		// Note that the previous line wasn't really efficient
		// because we create the option, this option is duplicated
		// for the request and then the option destructor is called.
		// You can use this instead:
		myRequest.setOpt(new curlpp::options::Url("example.com"));
		// Note that with this the request will use directly this
		// instance we just created. Be aware that if you pass an
		// Option pointer to the setOpt function, it will consider
		// the instance has its own instance. The Option instance
		// will be deleted when the request will be deleted, so
		// don't use the instance further in your code.


		// Doing the previous line is efficient as this:
		myRequest.setOpt(myUrl.clone());


		// You can retreive the value of a specific option.
		std::cout << myUrl2.getValue() << std::endl;

		// Perform the transaction with the options set.
		myRequest.perform();
	}

	catch( curlpp::RuntimeError &e )
	{
		std::cout << e.what() << std::endl;
	}

	catch( curlpp::LogicError &e )
	{
		std::cout << e.what() << std::endl;
	}
    
  return 0;
}
示例#4
0
void Service::start()
{
    // Den Port einlesen und den SSL-Server starten

    // Ini-Datei öffenen
    QSettings serviceSettings (QCoreApplication::applicationDirPath() + QLatin1String("/service.ini"), QSettings::IniFormat);
    //
    quint16 myPort (serviceSettings.value(QLatin1String("ports/service"), 3656).toInt());
    // Client port
    quint16 clientPort (serviceSettings.value(QLatin1String("ports/client"), 3655).toInt());

    // Debug an/ ausschalten
    Debug::setDebugPath(QCoreApplication::applicationDirPath());
    Debug::enableDebugging(serviceSettings.value(QLatin1String("debug/state"), 0).toBool());
    int debLev (serviceSettings.value(QLatin1String("debug/level"), 9).toInt());
    switch (debLev) {
        case 1:
            Debug::setDebugLevel(DebugLevel::Error);
            break;
        case 2:
            Debug::setDebugLevel(DebugLevel::Category);
            break;
        case 3:
            Debug::setDebugLevel(DebugLevel::Function);
            break;
        case 4:
            Debug::setDebugLevel(DebugLevel::Comment);
            break;
        case 5:
            Debug::setDebugLevel(DebugLevel::Database);
            break;
        case 6:
            Debug::setDebugLevel(DebugLevel::Debug);
            break;
        case 7:
            Debug::setDebugLevel(DebugLevel::Construktor);
            break;
        case 8:
            Debug::setDebugLevel(DebugLevel::Destruktor);
            break;
        case 9:
            Debug::setDebugLevel(DebugLevel::All);
            break;
        case 0:
        default:
            Debug::setDebugLevel(DebugLevel::None);
            break;
    }

    Debug::enableDateTime(serviceSettings.value(QLatin1String("debug/date"), 1).toBool());
    Debug::enableMSecs(serviceSettings.value(QLatin1String("debug/msecs"), 1).toBool());



    // Den Client Port in der SrvCli setzen
    SrvCLI::instance()->setPort(clientPort);

    Debug::log(QString("Starting service on port %1").arg(myPort));
    Debug::log(QString("Client is listing on port %1").arg(clientPort));

    // SSL Server starten
    this->server = new SslServer(myPort, this);
}
示例#5
0
文件: MyroC.cpp 项目: zrafa/se_uncoma
// turns the C string into a C++ string and connects to that port
extern "C" void 
rConnect (const char * port)
{
  std::string myPort (port);
  connect (myPort);
}
示例#6
0
/** 
 * This example is made to show you how you can use the Options.
 */
int main(int, char **)
{
  try
    {
      cURLpp::Cleanup myCleanup;

      // Creation of the URL option.
      cURLpp::Options::Url myUrl(std::string("http://example.com"));
      
      // Copy construct from the other URL.
      cURLpp::Options::Url myUrl2(myUrl);

      // Creation of the port option.
      cURLpp::Options::Port myPort(MY_PORT);

      // Creation of the request.
      cURLpp::Easy myRequest;


      // Creation of an option that contain a copy of the URL option.
      cURLpp::OptionBase *mytest = myUrl.clone();
      myRequest.setOpt(*mytest);

      // You can reuse the base option for other type of option
      // and set the option to the request. but first, don't forget 
      // to delete the previous memory. You can delete it since the 
      // option is internally duplicated for the request.
      delete mytest;
      mytest = myPort.clone();
      myRequest.setOpt(*mytest);
      delete mytest;

      // You can clone an option directly to the same type of 
      // option.
      cURLpp::Options::Url *myUrl3 = myUrl.clone();
      myRequest.setOpt(myUrl3);
      // Now myUrl3 is owned by the request we will NOT use 
      // it anymore.


      // You don't need to declare an option if you just want 
      // to use it once.
      myRequest.setOpt(cURLpp::Options::Url("example.com"));
      

      // Note that the previous line wasn't really efficient
      // because we create the option, this option is duplicated
      // for the request and then the option destructor is called.
      // You can use this instead:
      myRequest.setOpt(new cURLpp::Options::Url("example.com"));
      // Note that with this the request will use directly this
      // instance we just created. Be aware that if you pass an
      // Option pointer to the setOpt function, it will consider
      // the instance has its own instance. The Option instance
      // will be deleted when the request will be deleted, so
      // don't use the instance further in your code.


      // Doing the previous line is efficient as this:
      myRequest.setOpt(myUrl.clone());

      
      // You can retreive the value of a specific option.
      std::cout << myUrl2.getValue() << std::endl;

      // Perform the transaction with the options set.
      myRequest.perform();
    }
  catch( cURLpp::RuntimeError &e )
    {
      std::cout << e.what() << std::endl;
    }
  catch( cURLpp::LogicError &e )
    {
      std::cout << e.what() << std::endl;
    }
    
  return 0;
}