示例#1
0
void ServerNet::clientWrite(int clientId, ISocket *sock, char *data, int size)
{
  (void)clientId;
  if (select_.getProtocol() == protocolId::TCP)
  {
    this->sendData(sock, data, size);
  }
  else if (select_.getProtocol() == protocolId::UDP)
  {
    ISocket *server = select_.getSocket();
    server->setRecvAddr(sock->getRecvAddr());
    server->send(data, size);
  }
  delete[] data;
}
示例#2
0
文件: size.cpp 项目: samikama/yampl
void server(ISocketFactory *factory, const Channel &channel){
  char *buffer = new char[100];
  ISocket *socket = factory->createServerSocket(channel);

  try{
    socket->recv(buffer, 1);
  }catch(InvalidSizeException){
    socket->recv(buffer, 100);
  }

  assert(strcmp(buffer, message) == 0);
  socket->send(message);

  delete socket;
  delete factory;
}
示例#3
0
static void* clientCallback(void* arg)
{
  ClientData* data = static_cast<ClientData*>(arg);
  std::string host = "127.0.0.2";
  if (!data->isServer)
      host = "127.0.0.1";

  try
    {
      ISocket* client = new Socket();

      if (client->run(host))
	{
	  IAudioIO* audioIO = new PortAudio;

	  while (client->isConnected())
	    {
	      //	      std::string tosend = "recorded.. from " + data->login;
	      audioIO->startRecord(RECORD_TIME);
	      AudioData* data = audioIO->getRecorded();

	      client->send(data->getData(), data->getSize());
	      //	      sleep(1);
	    }
	  delete audioIO;
	}
      delete client;
      data->clientThread->exit();
    }    
  catch (ISocket::Exception& e)
    {
      std::cerr << e.what() << std::endl; 
    }
  catch (IAudioIO::Exception& e)
    {
      std::cerr << e.what() << std::endl; 
    }
  return NULL;
}