예제 #1
0
RpcStringBinding::RpcStringBinding
    (
    DUALSTRINGARRAY*    pdsa,
    int			portNumber
    )
  : m_ipAddress (0),
    m_portNumber (portNumber),
    m_protocolSeq (0),
    m_strFormat (0),
    m_strFormatNoPortNumber (0)
    {
    // Check the DUALSTRINGARRAY entries, to find one which can be
    // 'resolved' into an IP address on this machine. Win2K sometimes
    // provides hostnames as well as the IP numbers that NT usually
    // sends, so we need to scan the array to find an IP number...
    OLECHAR* pStart = pdsa->aStringArray;
    OLECHAR* pCurr = pStart;
    
    while ((pCurr - pStart) < pdsa->wNumEntries)
        {
        // Make a string-binding out of the DSA entry...
	char * pStr = new char [comWideStrLen (pCurr + 1) + 1];
	comWideToAscii (pStr, pCurr + 1, comWideStrLen (pCurr + 1) + 1);
        initialiseFromString (pStr);
	delete []pStr;
        m_protocolSeq  = *pCurr;

        // See if it can be 'resolved' into a viable IP number...
        if (! resolve ())
            {
            S_ERR (LOG_DCOM, "Could not resolve " << ipAddress ());

            // Free up the allocated strings.
            delString (m_ipAddress);
            delString (m_strFormat);
            delString (m_strFormatNoPortNumber);

            // Could not make sense of the address, so move on through
            // the array to the next entry, or the end of the array...
            while (((pCurr - pStart) < pdsa->wNumEntries) && (*pCurr))
                ++pCurr;

            ++pCurr;
            }
        else
            {
            S_INFO (LOG_DCOM, "Resolved " << ipAddress ());

            // Take the first one that is viable...
            break;
            }
        }
    // at this point the string binding may have worked or not so the calling
    // routine must make a call to resolve to determine if a valid address was
    // bound since the constructor can't /init
    }
예제 #2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setFixedSize(467, 304);
    bytesSent = 0;
    ui->lineEdit_localPort->setEnabled(false);
    ui->lineEdit_filePath->setEnabled(false);
    ui->lineEdit_localAddress->setEnabled(false);
    ui->lineEdit_remoteAddress->setEnabled(false);
    ui->progressBar->setValue(0);
    ui->progressBar->setRange(0, 10000);

    connect(&server, SIGNAL(currentStatus(int)), this, SLOT(setCurrentStatus(int)));
    connect(&server, SIGNAL(error(int)), this, SLOT(errorHandler(int)));
    connect(&server, SIGNAL(ipAddress(QString, quint16)),this, SLOT(displayIPAddress(QString, quint16)));
    connect(&server, SIGNAL(bytesSent(qint64)), this, SLOT(updateProgressBar(qint64)));
    connect(&server, SIGNAL(progressRange(qint64)), this, SLOT(setProgressRange(qint64)));

    QFile thePath("C:/imageFilePath_inkPresettingSystem");
    if (thePath.open(QIODevice::ReadOnly)){
        QString dir = thePath.readAll();
        ui->lineEdit_filePath->setText(dir);

        server.setFilePath(dir);
        thePath.close();
    }
}
예제 #3
0
// Send treatment plan
void Server::sendPlan()
{
    QHostAddress ipAddress("172.168.0.116");
    m_tcpServer->connectToHost(ipAddress, 6666);

    QDataStream m_sendOut(&m_outBlock, QIODevice::WriteOnly);
    m_sendOut.setVersion(QDataStream::Qt_4_6);

    qDebug() << "Sending plan...";
    QString sendInfo = writeSendInfo();

    // Write data
    connect(m_tcpServer, SIGNAL(bytesWritten(qint64)), this, SLOT(writtenBytes(qint64)));    // Check if the data has been all well written

    m_sendOut << qint64(0)
              << qint64(0)
              << m_plan.coordinate.spotNum
              << m_plan.coordinate.spotPosX
              << m_plan.coordinate.spotPosY
              << m_plan.coordinate.spotPosZ
              << m_plan.parameter.coolingTime
              << m_plan.parameter.dutyCycle
              << m_plan.parameter.sonicationPeriod
              << m_plan.parameter.sonicationTime
              << sendInfo;

    qDebug() << "sendInfo:" << sendInfo;

    m_totalBytes = m_outBlock.size();
    qDebug() << "m_totalBytes:" << m_totalBytes;
    m_sendOut.device()->seek(0);
    m_sendOut << qint64(2) << m_totalBytes;    // Find the head of array and write the haed information

    m_tcpServer->write(m_outBlock);

    m_sendTimeNum += 1;
    m_writtenBytes = 0;
    m_outBlock.resize(0);

    qDebug() << "Send finished";

    // Read send-back data
    connect(m_tcpServer, SIGNAL(readyRead()), this, SLOT(readSendBack()));

    m_tcpServer->waitForReadyRead(3000);

    qDebug() << m_receivedInfo;

    // Check the consistency of the send-back data
    if(m_receivedInfo == sendInfo)
    {
        qDebug() << "Send-back checked.";
        m_receivedInfo = "";
    }
    else
    {
        emit error_sendBackCheck();
        qDebug() << "Check failed ! emit error signal...";
    }
}
예제 #4
0
void WebUser::disconnect()
{
	qDebug() << QString("WebSocket on %1 disconnecting").arg(ipAddress());

	socket_->flush();
	socket_->close();
}
예제 #5
0
void Tranceiver::connect(String ipAddr) {
	semaphore.Acquire();

	//create socket
	socket=new Socket();
	socket->Construct(NET_SOCKET_AF_IPV4,
			NET_SOCKET_TYPE_STREAM, NET_SOCKET_PROTOCOL_TCP);

	unsigned long blockingModeSocket=0;
	socket->Ioctl(NET_SOCKET_FIONBIO, blockingModeSocket);

	//Connect to TCP Server
	Ip4Address ipAddress(ipAddr);
	NetEndPoint endPoint(ipAddress, PORT);
	result r=socket->Connect(endPoint);

	if(r!=E_SUCCESS) {
		AppLogException("CommandCenter : Connect Error");
	}

	//Create Packet Object
	packetSender=new PacketSender(socket);
	screenSender=new ScreenSender(socket);
	packetReceiver=new PacketReceiver(socket);

	//Start PacketReciever
	packetReceiver->setPacketListener(this);
	packetReceiver->Construct();
	packetReceiver->flag=true;
	packetReceiver->Start();

	//mServerConnectionListener->onServerConnected(ipAddr);

	semaphore.Release();
}
예제 #6
0
void DesktopUser::disconnect()
{
	qDebug() << QString("TCP Socket on %1 disconnecting").arg(ipAddress());

	socket_->flush();
	socket_->disconnectFromHost();
}
예제 #7
0
void Devices::getLocalIpAddresses(const pcap_if_t *dev,std::vector<ipAddress> &addresses) const {
    std::vector<QString> localAddress;

    for(pcap_addr_t *address=dev->addresses; address!=NULL; address=address->next) {
        if(address->addr->sa_family == AF_INET)
            localAddress.push_back(QString(inet_ntoa(((struct sockaddr_in*)address->addr)->sin_addr)));
    }

    addresses.clear();
    for (QString str: localAddress) {
        addresses.push_back(ipAddress(str));
    }
}
예제 #8
0
// Send command resume
void Server::sendCommandResume()
{
    QHostAddress ipAddress("172.168.0.116");
    m_tcpServer->connectToHost(ipAddress, 6666);

    QDataStream m_sendOut(&m_outBlock, QIODevice::WriteOnly);
    m_sendOut.setVersion(QDataStream::Qt_4_6);

    qDebug() << "Sending command start...";

    m_sendOut << qint64(1);
    m_sendOut << qint64(4);

    m_tcpServer->write(m_outBlock);
    m_outBlock.resize(0);

    m_tcpServer->close();
    qDebug() << "Send finished";
}
예제 #9
0
void TcpConnection::connect()
{
  // if connection is already established, then method do nothing.
  {
    AutoLock al(&m_connectLock);
    m_wasConnected = true;
  }
  // need create to gates
  if (m_input == 0 && m_output == 0) {
    // need create to socket
    if (m_socket == 0) {
      if (!m_host.isEmpty() && m_port != 0) {
        SocketAddressIPv4 ipAddress(m_host.getString(), m_port);

        StringStorage ipAddressString;
        ipAddress.toString(&ipAddressString);
        m_logWriter->detail(_T("Connecting to the host \"%s:%hd\" (%s:%hd)..."),
                            m_host.getString(), m_port,
                            ipAddressString.getString(), m_port);

        m_socket = new SocketIPv4;
        m_socketOwner = true;
        m_socket->connect(ipAddress);
        m_socket->enableNaggleAlgorithm(false);
      } else {
        throw Exception(_T("Connection parameters (host, port, socket, gates) is empty."));
      }
    }

    m_logWriter->detail(_T("Initialization of socket stream and input/output gates..."));
    m_socketStream = new SocketStream(m_socket);

    m_input = new RfbInputGate(m_socketStream);
    m_output = new RfbOutputGate(m_socketStream);
    m_RfbGatesOwner = true;
  } else {
    _ASSERT(m_input != 0 && m_output != 0);
  }
  {
    AutoLock al(&m_connectLock);
    m_isEstablished = true;
  }
}
예제 #10
0
const char* RpcStringBinding::formatted (bool includePortNumber) const
    {
    char*& p = includePortNumber ? m_strFormat : m_strFormatNoPortNumber;

    if (p == 0 && m_ipAddress != 0)
	{
	char binding [MAXHOSTNAMELEN]; // XXX

	int n = 0;

	n = ::sprintf (binding, "%c%s", protocolSequence (), ipAddress ());

	if (n && includePortNumber)
	    ::sprintf (&binding[n], "[%d]", portNumber ());

	p = copyString (binding);
	}

    return p;
    }
예제 #11
0
void LoginState::createGUIWindow()
{
  assert(pGui);

    // Load the previous login settings from login.cfg, if one exists
  std::string ipAddress(""), playerName("nameless newbie");
  float colorSelection = 0.0f;
  Ogre::ConfigFile loginConfig;
  try {
      loginConfig.load(bundlePath() + "login.cfg");
      ipAddress = loginConfig.getSetting("IPaddress");
      playerName = loginConfig.getSetting("PlayerName");
      if (!from_string<float>(colorSelection, loginConfig.getSetting("PlayerColor"), std::dec))
        colorSelection = 0.0f;
  } catch (Ogre::FileNotFoundException e) {}

  pGui->setupLoginWindow(ipAddress, playerName, colorSelection);
  pGui->setLoginReceiver(this);

  mViewport = new MenuStateViewport(pSceneManager);
}
예제 #12
0
int main(int argc, char** argv)
{

	std::string ipAddress("");
	if (argc > 1)
	{
		if (stricmp(argv[1], "--server") == 0)
		{
			g_networkPtr = new TetrisServer();
		}
		else
		{
			ipAddress = argv[1];
			g_networkPtr = new TetrisClient(ipAddress);
		}
	}

	if (g_networkPtr != NULL)
	{
		if (!g_networkPtr->Init())
		{
			delete g_networkPtr;
			g_networkPtr = NULL;
		}
	}

	sf::RenderWindow window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "SFML TETRIS");
	
	sf::View playerView;
	GameManager gameMgr;
	Tetris* localGame = new Tetris();
	localGame->Init();
	gameMgr.AddGame(localGame, sf::FloatRect(.5, 0, 0.4, .4));

	Tetris* otherGame = new Tetris();
	otherGame->Init();
	gameMgr.AddGame(otherGame, sf::FloatRect(0.5, 0.5, .4, 0.4));
	
	
	sf::Clock clock;

	while (window.isOpen() && gameMgr.IsRunning())
	{
		if (g_networkPtr != NULL)
		{
			g_networkPtr->Loop();
		}

		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();
		}
		
		sf::Time time = clock.restart();
		gameMgr.Update(&window, time.asSeconds());
				
		//window.setView(window.getDefaultView());
		//window.clear(sf::Color(40, 40, 40));
		//game.Draw(&window);
		
		window.display();
	}

	if (g_networkPtr != NULL)
	{
		delete g_networkPtr;
		g_networkPtr = NULL;
	}
	return 0;
}
예제 #13
0
// Connect to client and start session
void Server::connectServer()
{
    // Initialize the sent data as 0
    QHostAddress ipAddress("172.168.0.116");
    m_tcpServer->connectToHost(ipAddress, 6666);    // Connect
}
예제 #14
0
cString IA32IntelNotation::string(OpcodeFormatStruct* formatStruct) const
{
    // Get the instruction address
    ProcessorAddress ipAddress(gNullPointerProcessorAddress);
    bool shouldUseIp = m_data->getOpcodeAddress(ipAddress);

    // Mark new instruction
    m_dataFormatter.newInstruction(shouldUseIp, ipAddress);

    // Add all the prepost-prefix name
    cString ret;

    // Add all the prepost-prefix name
    for (uint i = 0; i < m_opcode->m_prefixsCount; i++)
        for (uint j = 0; j < ia32dis::IA32_NUMBER_OF_PREFIXS; j++)
            if ((m_opcode->m_prefixs[i] == ia32dis::gIa32PrefixTable[j].m_opcode) &&
                (!ia32dis::gIa32PrefixTable[j].m_isSegmentSelector) &&
                (ia32dis::gIa32PrefixTable[j].m_isOpcodeNameValid))
            {
                ret+= ia32dis::gIa32PrefixTable[j].m_prefixName;
                ret+= " ";
            }

    if (formatStruct != NULL)
        formatStruct->m_opcodeNameStart = ret.length();

    // Add the opcode name
    cString opcodeName = m_opcode->m_opcode->m_opcodeName;
    // Replace name convenstion
    if (opcodeName.find("/") < opcodeName.length())
    {
        // TODO! 64bit
        if (is32bit())
            opcodeName = opcodeName.left(opcodeName.find("/"));
        else
            opcodeName = opcodeName.part(opcodeName.find("/") + 1,
                                         opcodeName.length() - 1);
    }

    uint namePos = opcodeName.find("#");
    while (namePos != opcodeName.length()) {
        switch (opcodeName[namePos + 1])
        {
        case XSTL_CHAR('d'):
            opcodeName = opcodeName.left(namePos) +
                (is32bit() ? "d" : "") +
                opcodeName.part(namePos + 2, opcodeName.length() - 1);
            break;
        case XSTL_CHAR('e'):
            opcodeName = opcodeName.left(namePos) +
                (is32bit() ? "e" : "") +
                opcodeName.part(namePos + 2, opcodeName.length() - 1);
            break;
        case XSTL_CHAR('#'):
            opcodeName = opcodeName.left(namePos) +
                (is32bit() ? "d" : "w") +
                opcodeName.part(namePos + 2, opcodeName.length() - 1);
            break;
        }
        namePos = opcodeName.find("#");
    }

    ret+= m_dataFormatter.reparseOpcode(opcodeName);

    if (formatStruct != NULL)
        formatStruct->m_opcodeOperandsStart = ret.length();

    // Start adding operands
    // Add operands
    if (m_opcode->m_opcode->m_firstOperand == ia32dis::OPND_NO_OPERAND)
    {
        ASSERT(m_opcode->m_opcode->m_secondOperand == ia32dis::OPND_NO_OPERAND);
        ASSERT(m_opcode->m_opcode->m_thridOperand == ia32dis::OPND_NO_OPERAND);
        return m_dataFormatter.endInstruction(ret);
    }

    ret+= m_dataFormatter.reparseFirstOperand(
                    stringOperand(m_opcode->m_opcode->m_firstOperand));

    if (m_opcode->m_opcode->m_secondOperand == ia32dis::OPND_NO_OPERAND)
    {
        ASSERT(m_opcode->m_opcode->m_thridOperand == ia32dis::OPND_NO_OPERAND);
        return m_dataFormatter.endInstruction(ret);
    }

    // Pad with space and first operand
    ret+= m_dataFormatter.getOpcodesSeparator(ret);
    ret+= m_dataFormatter.reparseSecondOperand(
                    stringOperand(m_opcode->m_opcode->m_secondOperand));

    if (m_opcode->m_opcode->m_thridOperand == ia32dis::OPND_NO_OPERAND)
        return m_dataFormatter.endInstruction(ret);

    ret+= m_dataFormatter.getOpcodesSeparator(ret);
    ret+= m_dataFormatter.reparseThirdOperand(
                    stringOperand(m_opcode->m_opcode->m_thridOperand));

    // Build the instruction
    return m_dataFormatter.endInstruction(ret);
}