Esempio n. 1
0
void wxMainFrame::OnSocketEvent(wxSocketEvent& event)
{
  if (event.GetSocketEvent()==wxSOCKET_INPUT)
  {
//    m_TEDProtocol->GetSocketData();
  }
  else if (event.GetSocketEvent()==wxSOCKET_LOST)
  {
    ::wxMessageBox(_("Se perdió la conexión con el servidor.\nEl cliente se cerrará."));
    Close();
  }
}
Esempio n. 2
0
void CslUDP::OnSocketEvent(wxSocketEvent& event)
{
    if (event.GetSocketEvent()!=wxSOCKET_INPUT)
        return;

    wxIPV4address addr;
    wxUint32 size;
    CslUDPPacket *packet=new CslUDPPacket(CSL_MAX_PACKET_SIZE);

    m_socket->RecvFrom(addr,packet->Data(),CSL_MAX_PACKET_SIZE);

    if (m_socket->Error())
    {
        packet->FreeData();
#ifndef __WXMSW__
        LOG_DEBUG("Error receiving packet: %s\n",U2A(GetSocketError(m_socket->LastError())));
#endif
    }

    size=m_socket->LastCount();
    packet->SetAddr(addr);
    packet->SetSize(size);
    m_bytesIn+=size;
    m_packetsIn++;

    wxCommandEvent evt(wxCSL_EVT_PING);
    evt.SetClientData(packet);
    wxPostEvent(m_evtHandler,evt);
}
Esempio n. 3
0
void FaceView::OnSocketEvent(wxSocketEvent& event)
{
	wxSocketBase *sock = event.GetSocket();
	static int test = 0;
	// Now we process the event
	switch(event.GetSocketEvent())
	{
		case wxSOCKET_INPUT:
		{
			wxString msg;
			msg.sprintf(_T("input id: %d"), ++test);
			sock->SaveState();
//			sock->SetNotify(wxSOCKET_LOST_FLAG);
			wxLogStatus(msg, 0);
			ServerThread* pThread = new ServerThread(/*this, */m_pApp, sock);
			pThread->Create();
			pThread->Run();
			sock->RestoreState();

			//sock->SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG);
			break;
		}
		case wxSOCKET_LOST:
		{
			if(!m_SocketIdHash.erase(sock))
			{
				//sth weird going on, LOG IT!
			}
			sock->Destroy();
			wxLogStatus(wxT("Remote client connection closed."));
			break;
		}
		default: ;
	}
}
Esempio n. 4
0
/* Function called on every client request.
 */
void EDA_DRAW_FRAME::OnSockRequest( wxSocketEvent& evt )
{
    size_t        len;
    wxSocketBase* sock = evt.GetSocket();

    switch( evt.GetSocketEvent() )
    {
    case wxSOCKET_INPUT:
        sock->Read( client_ipc_buffer, 1 );

        if( sock->LastCount() == 0 )
            break;                    // No data, occurs on opening connection

        sock->Read( client_ipc_buffer + 1, IPC_BUF_SIZE - 2 );
        len = 1 + sock->LastCount();
        client_ipc_buffer[len] = 0;
        ExecuteRemoteCommand( client_ipc_buffer );
        break;

    case wxSOCKET_LOST:
        return;
        break;

    default:
        wxPrintf( wxT( "EDA_DRAW_FRAME::OnSockRequest() error: Invalid event !" ) );
        break;
    }
}
Esempio n. 5
0
// Handle Commands from debugger (and lost connections)
void wxLuaDebuggerwxSocketServer::OnSocketEvent(wxSocketEvent& event)
{
    wxSocketBase *sock = event.GetSocket();

    // Now we process the event
    switch(event.GetSocketEvent())
    {
        case wxSOCKET_INPUT:
        {
            // We disable input events, so that the test doesn't trigger
            // wxSocketEvent again.
            sock->SetNotify(wxSOCKET_LOST_FLAG);

            unsigned char debugEvent = 0; // wxLuaDebuggeeEvents_Type
            if (m_acceptedSocket->ReadCmd(debugEvent))
                HandleDebuggeeEvent(debugEvent);

            // Enable input events again.
            sock->SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG);
            break;
        }
        case wxSOCKET_LOST:
        {
            m_acceptedSocket->Destroy();
            delete m_acceptedSocket;
            m_acceptedSocket = NULL;
            break;
        }
        default:
            // Error
            break;
    }
}
Esempio n. 6
0
void CRealControlSocket::OnSocketEvent(wxSocketEvent &event)
{
	if (!m_pBackend)
		return;

	if (event.GetId() != m_pBackend->GetId())
		return;

	switch (event.GetSocketEvent())
	{
	case wxSOCKET_CONNECTION:
		m_onConnectCalled = true;
		OnConnect();
		break;
	case wxSOCKET_INPUT:
		if (!m_onConnectCalled)
		{
			m_onConnectCalled = true;
			OnConnect();
		}
		OnReceive();
		break;
	case wxSOCKET_OUTPUT:
		OnSend();
		break;
	case wxSOCKET_LOST:
		OnClose();
		break;
	}
}
Esempio n. 7
0
void WinEDA_DrawFrame::OnSockRequest(wxSocketEvent& evt)
/********************************************************/
/* Fonction appelee a chaque demande d'un client
*/
{
    size_t len;
    wxSocketBase *sock = evt.GetSocket();

    switch (evt.GetSocketEvent())
    {
    case wxSOCKET_INPUT:
        sock->Read(server_ipc_buffer,1);
        len = sock->Read(server_ipc_buffer+1,IPC_BUF_SIZE-2).LastCount();
        server_ipc_buffer[len+1] = 0;
        if(RemoteFct ) RemoteFct(server_ipc_buffer);
        break;

    case wxSOCKET_LOST:
        return;
        break;

    default:
        wxPrintf( wxT("WinEDA_DrawFrame::OnSockRequest() error: Invalid event !"));
        break;
    }
}
Esempio n. 8
0
void FaceView::OnServerEvent(wxSocketEvent& event)
{
    wxString s;
    wxSocketBase *sock = 0;

    if(event.GetSocketEvent() != wxSOCKET_CONNECTION)
        return;

    // Accept new connection if there is one in the pending
    // connections queue, else exit. We use Accept(FALSE) for
    // non-blocking accept (although if we got here, there
    // should ALWAYS be a pending connection).
    sock = m_pServer->Accept(false);

    if (sock)
    {
        wxLogStatus(_T("New client connection accepted"), 0);
        m_SocketIdHash[sock] = ++m_clientCount; // add socket to map of connected clients

        // Notify the client
        Notification note("CONNECTION_OK", m_clientCount);
        fireNotification(note);
    }
    else
        return;

    sock->SetEventHandler(*this, Socket_event);
    sock->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
    sock->Notify(TRUE);
}
Esempio n. 9
0
void CslUDP::OnSocketEvent(wxSocketEvent& event)
{
    if (event.GetSocketEvent()!=wxSOCKET_INPUT)
        return;

    wxInt32 read;
    wxIPV4address addr;
    CslNetPacket *packet = CslNetPacket::Create();
    packet->Alloc(CSL_MAX_PACKET_SIZE);

    if (m_socket->RecvFrom(addr, packet->Data(), CSL_MAX_PACKET_SIZE).Error())
    {
#ifndef __WXMSW__
        CSL_LOG_DEBUG("error RecvFrom() failed. (%s)\n",
                      U2C(GetSocketError(m_socket->LastError())));
#endif
        CslNetPacket::Destroy(packet, true);
        return;
    }

    if ((read = m_socket->LastCount())==0)
    {
        CslNetPacket::Destroy(packet, true);
        return;
    }

    packet->SetAddr(addr);
    packet->SetSize(read);

    m_bytesIn += read;
    m_packetsIn++;

    CslPingEvent evt(packet);
    wxPostEvent(m_evtHandler, evt);
}
Esempio n. 10
0
void SocketEvents::OnSocketEvent(wxSocketEvent& event)
{
	Socket* sock = (Socket*)event.GetClientData();
	if (sock == NULL) {
		m_net_class.OnError(_T("sock = 0"));
		return;
	}

	if ( event.GetSocketEvent() == wxSOCKET_INPUT ) {
		m_net_class.OnDataReceived( *sock );
	} else if ( event.GetSocketEvent() == wxSOCKET_LOST ) {
		m_net_class.OnDisconnected( *sock );
	} else if ( event.GetSocketEvent() == wxSOCKET_CONNECTION ) {
		m_net_class.OnConnected( *sock );
	} else {
		m_net_class.OnError(_T("Unknown socket event."));
	}
}
Esempio n. 11
0
void CProxyEventHandler::ProxySocketHandler(wxSocketEvent& event)
{
	CProxySocket *sock = dynamic_cast<CProxySocket *>(event.GetSocket());
	if (sock) {
		sock->m_proxyStateMachine->Schedule(event.GetSocketEvent());
	} else {
		// we're doomed :)
	}
	sock->m_proxyStateMachine->Clock();
}
Esempio n. 12
0
void CServerConsole::OnSocketEvent(wxSocketEvent& event){
	wxSocketBase *sock = event.GetSocket();
	switch(event.GetSocketEvent()){
		case wxSOCKET_LOST:{
			Log(wxString::FromAscii("Client disconnected"));
			sock->Destroy();
			break;
		}
		case wxSOCKET_INPUT:{
			// Disable input events, not to trigger wxSocketEvent again
			sock->SetNotify(wxSOCKET_LOST_FLAG);

			ClientHandshake	handshake;
			sock->ReadMsg(&handshake, sizeof(handshake));
			if (sock->Error()){
				Log(wxString::FromAscii("Error receiving client message"));
				sock->Close();
				return;
			}

                        Log(wxString::FromAscii("Got a handshake"));

			int iClientID = handshake.id;
			if ((iClientID == -1) || ((iClientID > 0) && !IsClientIDValid(iClientID))){
				iClientID = CreateNewClient(iClientID);
			}

			ServerReply	reply;
			reply.id = iClientID;
			reply.status = 1;

			if (!IsClientIDValid(iClientID))
				reply.status = -1;

			sock->WriteMsg(&reply, sizeof(reply));
			if (sock->Error()){
				Log(wxString::FromAscii("Error sending a reply"));
				return;
			}
			Log(wxString::FromAscii("Sent a reply"));

			if (!IsClientIDValid(iClientID))
				return;

			ReceiveClientCommand(iClientID, sock);

			// Enable input events again.
			sock->SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG);

			break;
		}
		default:
			wxASSERT(0);
	}
}
Esempio n. 13
0
void wxScopeServerDialog::OnSocketEvent(wxSocketEvent& event)
{
  wxString s = _("OnSocketEvent: ");
  wxSocketBase *sock = event.GetSocket();
/*
  // First, print a message
  switch(event.GetSocketEvent())
  {
    case wxSOCKET_INPUT : s.Append(_("wxSOCKET_INPUT\n")); break;
    case wxSOCKET_LOST  : s.Append(_("wxSOCKET_LOST\n")); break;
    default             : s.Append(_("Unexpected event !\n")); break;
  }
  Tx_ServerLog->AppendText(s);
*/

  // Now we process the event
  switch(event.GetSocketEvent())
  {
    case wxSOCKET_INPUT:
    {
      // We disable input events, so that the test doesn't trigger
      // wxSocketEvent again.
      sock->SetNotify(wxSOCKET_LOST_FLAG);

      if (!m_server->HandleINPUT(sock)) // delegate input handling to class
         Tx_ServerLog->AppendText(_("HandleINPUT failed\n"));

      // Enable input events again.
      sock->SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG);
      break;
    }
    case wxSOCKET_LOST:
    {
      m_numClients--;

      // Destroy() should be used instead of delete wherever possible,
      // due to the fact that wxSocket uses 'delayed events' (see the
      // documentation for wxPostEvent) and we don't want an event to
      // arrive to the event handler (the frame, here) after the socket
      // has been deleted. Also, we might be doing some other thing with
      // the socket at the same time; for example, we might be in the
      // middle of a test or something. Destroy() takes care of all
      // this for us.

      Tx_ServerLog->AppendText(_("Closing socket.\n\n"));
      sock->Notify(false);
      sock->Destroy();
      break;
    }
    default: ;
  }

}
Esempio n. 14
0
void SocketEvents::OnSocketEvent(wxSocketEvent& event)
{
  Socket* sock = (Socket*)event.GetClientData();
  try
  {
  ASSERT_LOGIC( sock != 0, _T("sock = 0") );
  } catch (...) { return; }

  if ( event.GetSocketEvent() == wxSOCKET_INPUT ) {
    m_net_class.OnDataReceived( sock );
  } else if ( event.GetSocketEvent() == wxSOCKET_LOST ) {
    m_net_class.OnDisconnected( sock );
  } else if ( event.GetSocketEvent() == wxSOCKET_CONNECTION ) {
    m_net_class.OnConnected( sock );
  } else {
    try
    {
    ASSERT_LOGIC( false, _T("Unknown socket event."));
    } catch (...) { return; };
  }
}
/*!
 *  Handler for Server events (before connection)
 *
 *  - Only expects connection events wxSOCKET_CONNECTION
 *  - Creates new socket and adds handler for socket events
 *
 *  @param event Event to handle
 */
void GdbServerWindow::OnServerEvent(wxSocketEvent& event) {
   if (event.GetSocketEvent() != wxSOCKET_CONNECTION) {
      statusTextControl->AppendText(_("Unexpected event on Server\n"));
      // Ignore
      return;
   }

   if (clientSocket != NULL) {
      statusTextControl->AppendText(_("Client connection while busy - rejected\n"));
      wxSocketBase *clientSocket = serverSocket->Accept(false);
      clientSocket->Destroy();
      return;
   }

   // Accept new connection if there is one in the pending
   // connections queue, else exit. We use Accept(false) for
   // non-blocking accept (although if we got here, there
   // should ALWAYS be a pending connection).

   clientSocket = serverSocket->Accept(false);
   if (clientSocket == NULL) {
      statusTextControl->AppendText(_("Error: couldn't accept a new connection\n"));
      return;
   }

   IPaddress peerAddr;
   if ( !clientSocket->GetPeer(peerAddr) ) {
      statusTextControl->AppendText(_("New connection from unknown client accepted.\n"));
   }
   else {
      clientAddr = getAddr(peerAddr);
      statusTextControl->AppendText(_(
            "\n=====================================\n"
            "New client connection from ")+ clientAddr + _(" accepted\n"));
   }

   // Subscribe to socket events
   //  wxSOCKET_INPUT_FLAG - received data
   //  wxSOCKET_LOST_FLAG  - lost connection
   clientSocket->SetEventHandler(*this, SOCKET_ID);
   clientSocket->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
   clientSocket->Notify(true);

   setDeferredFail(false);
   deferredOpen = true;

   statusTimer = new wxTimer(this, SERVER_STATUSTIMER);
   statusTimer->Start(pollIntervalSlow, wxTIMER_ONE_SHOT);

   serverState = connected;
   UpdateStatusBar();
}
Esempio n. 16
0
void tracelogApp::OnSocketEvent(wxSocketEvent& event)
{
    wxSocketBase *sock = event.GetSocket();
    if (wxSOCKET_LOST == event.GetSocketEvent()) {
        sock->Notify(false);
        std::map<wxSocketBase *, wxSocketOutputStream *>::iterator it = m_mClients.find(sock);
        if (m_mClients.end() != it) {
            delete it->second;
            m_mClients.erase(it);
        }
        sock->Destroy();
    }
}
Esempio n. 17
0
void CTlsSocket::OnSocketEvent(wxSocketEvent& event)
{
	wxASSERT(m_pSocket);
	if (!m_session)
		return;

	if (event.GetId() != m_pSocketBackend->GetId())
		return;

	switch (event.GetSocketEvent())
	{
	case wxSOCKET_INPUT:
		OnRead();
		break;
	case wxSOCKET_OUTPUT:
		OnSend();
		break;
	case wxSOCKET_LOST:
		{
			m_canCheckCloseSocket = true;
			char tmp[100];
			m_pSocketBackend->Peek(&tmp, 100);
			if (!m_pSocketBackend->Error())
			{
				int lastCount = m_pSocketBackend->LastCount();

				if (lastCount)
					m_pOwner->LogMessage(Debug_Verbose, _T("CTlsSocket::OnSocketEvent(): pending data, postponing wxSOCKET_LOST"));
				else
					m_socketClosed = true;
				OnRead();

				if (lastCount)
					return;
			}

			m_pOwner->LogMessage(Debug_Info, _T("CTlsSocket::OnSocketEvent(): wxSOCKET_LOST received"));

			//Uninit();
			wxSocketEvent evt(GetId());
			evt.m_event = wxSOCKET_LOST;
			wxPostEvent(m_pEvtHandler, evt);
		}
		break;
	default:
		break;
	}
}
Esempio n. 18
0
void ConnectionMonitor::OnSocketEvent(wxSocketEvent& pEvent) {
	switch(pEvent.GetSocketEvent())
	{
	case wxSOCKET_INPUT:
		//Read
		break;
	case wxSOCKET_OUTPUT:
		//Write
		break;
	case wxSOCKET_CONNECTION:
		//Connection Established
		break;
	case wxSOCKET_LOST:
		//Connection Lost
		break;
	}
}
Esempio n. 19
0
void wxScopeServerDialog::OnServerEvent(wxSocketEvent& event)
{
  wxString s = _("OnServerEvent: ");
  wxSocketBase *sock;

  switch(event.GetSocketEvent())
  {
    case wxSOCKET_CONNECTION : s.Append(_("wxSOCKET_CONNECTION\n")); break;
    default                  : s.Append(_("Unexpected event !\n")); break;
  }

  Tx_ServerLog->AppendText(s);

  // Accept new connection if there is one in the pending
  // connections queue, else exit. We use Accept(false) for
  // non-blocking accept (although if we got here, there
  // should ALWAYS be a pending connection).

  // only accept one client at any time

  if(m_numClients == 0) {
     m_server->InitConnection();
     sock = m_server->Accept(false);

     if (sock)
     {
       Tx_ServerLog->AppendText(_("New client connection accepted\n\n"));
     }
     else
     {
       Tx_ServerLog->AppendText(_("Error: couldn't accept a new connection\n\n"));
       return;
     }

     sock->SetEventHandler(*this, SOCKET_ID);
     sock->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
     sock->Notify(true);
     sock->SetFlags(wxSOCKET_NOWAIT);

     m_numClients++;
  }
  else {
     Tx_ServerLog->AppendText(_("New client connection refused, server busy\n"));
  }
}
Esempio n. 20
0
/*------------------------------------------------------------------------------*/
void GRConnection::OnSocketEvent(wxSocketEvent& event)
{
	switch(event.GetSocketEvent()) 
	{
		case wxSOCKET_CONNECTION:
			OnConnect();
		break;

		case wxSOCKET_LOST:
			if(connecting == true) OnUnableToConnect();
			else if(connecting == false) OnDisconnect();
		break;

		case wxSOCKET_INPUT:
			OnDataAvailable();
		break;
	}
}
Esempio n. 21
0
void CServerConsole::OnServerEvent(wxSocketEvent& event)
{
	wxSocketBase *sock;
	wxASSERT(event.GetSocketEvent() == wxSOCKET_CONNECTION);
	sock = m_pServer->Accept(TRUE);
	if (sock){
		Log(wxString::FromAscii("New client connection accepted"));
	}else{
		Log(wxString::FromAscii("Error: couldn't accept a connection"));
		return;
	}

	sock->SetEventHandler(*this, ID_SOCKET_EVENT);
	sock->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
	sock->Notify(TRUE);
	
	sock->SetFlags(wxSOCKET_WAITALL/* | wxSOCKET_BLOCK*/);
}
Esempio n. 22
0
void kitchenFrame::OnSocketEvent(wxSocketEvent& event)
{
    wxSocketBase *sock = event.GetSocket();
    switch(event.GetSocketEvent())
    {
    case wxSOCKET_CONNECTION:
    {
//    wxMessageBox(_("Connected!"));
        break;
    }

    case wxSOCKET_INPUT:
    {

        sock->SetNotify(wxSOCKET_LOST_FLAG);

        unsigned char c;
        sock->Read(&c, 1);

        switch (c)
        {
        case 0xBE:
            readFromDining(sock);
            break; //this means we are receiving something from dining room f.e. new order
            //  case 0xCE: Test2(sock); break;
            //  case 0xDE: Test3(sock); break;
        }

        sock->SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG);
        break;
    }
    case wxSOCKET_LOST:
    {

//      wxMessageBox(_("DisConnected!"));
        StatusBar1->SetStatusText(_("Lost connection."),1);
//      sock->Destroy();
        sock->Close();
        break;
    }
    default:
        ;
    }
}
Esempio n. 23
0
void MyFrame::OnServerEvent(wxSocketEvent& event)
{
	txtRx->AppendText(wxT("OnServerEvent: "));
	wxSocketBase *sockBase;

	switch (event.GetSocketEvent())
	{
	case wxSOCKET_CONNECTION: txtRx->AppendText(wxT("wxSOCKET_CONNECTION\n")); break;
	default: txtRx->AppendText(wxT("Unexpected event !\n")); break;
	}

	// Accept new connection if there is one in the pending
	// connections queue, else exit. We use Accept(false) for
	// non-blocking accept (although if we got here, there
	// should ALWAYS be a pending connection).

	sockBase = sock->Accept(false);

	if (sockBase)
	{
		IPaddress addr;
		if (!sockBase->GetPeer(addr))
		{
			txtRx->AppendText(wxT("New connection from unknown client accepted.\n"));
		}
		else
		{
			txtRx->AppendText(wxString::Format(wxT("New client connection from %s:%u accepted \n"),
				addr.IPAddress(), addr.Service()));
		}
	}
	else
	{
		txtRx->AppendText(wxT("Error: couldn't accept a new connection \n"));
		return;
	}

	sockBase->SetEventHandler( *this, SOCKET_ID);
	sockBase->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
	sockBase->Notify(true);

	numClients++;
	SetStatusText(wxString::Format(wxT("%d  clients connected"),numClients), 1);
}
Esempio n. 24
0
void wxGISLocalClientConnection::OnSocketEvent(wxSocketEvent& event)
{
    event.Skip(false);
    wxLogDebug(wxT("wxClientTCPNetConnection: event"));
    switch(event.GetSocketEvent())
    {
        case wxSOCKET_INPUT:
            wxLogDebug(wxT("wxClientTCPNetConnection: INPUT"));
        break;
        case wxSOCKET_OUTPUT:
            wxLogDebug(wxT("wxClientTCPNetConnection: OUTPUT"));
            break;
        case wxSOCKET_CONNECTION:
            wxLogDebug(wxT("wxClientTCPNetConnection: CONNECTION"));
            m_bIsConnected = true;
            m_bIsConnecting = false;
            {
            wxNetMessage msgin(enumGISNetCmdHello, enumGISNetCmdStUnk, enumGISPriorityHighest);
            wxGISNetEvent event(0, wxGISNET_MSG, msgin);
            PostEvent(event);
            }
        break;
        case wxSOCKET_LOST:
            wxLogDebug(wxT("wxClientTCPNetConnection: LOST"));
            {
                wxNetMessage msgin(enumGISNetCmdBye, enumGISNetCmdStUnk, enumGISPriorityHighest);
                if(!m_bIsConnected && m_bIsConnecting)
                {
                    m_bIsConnecting = false;
                }
                else
                {
                    m_bIsConnected = false;
                }
                wxGISNetEvent event(0, wxGISNET_MSG, msgin);
                PostEvent(event);
            }
        break;
        default:
            wxLogDebug(wxT("wxClientTCPNetConnection: default"));
            break;
    }
}
Esempio n. 25
0
void wxGISLocalServerConnection::OnSocketEvent(wxSocketEvent& event)
{
    switch(event.GetSocketEvent())
    {
        case wxSOCKET_INPUT:
            //send event to advisers
            wxLogDebug(wxT("wxGISNetServerConnection: INPUT"));
            break;
        case wxSOCKET_OUTPUT:
            wxLogDebug(wxT("wxGISNetServerConnection: OUTPUT"));
            //ProcessNetMessage();
            break;
        case wxSOCKET_CONNECTION:
            wxLogDebug(wxT("wxGISNetServerConnection: CONNECTION"));
            break;
        case wxSOCKET_LOST:
            wxLogDebug(wxT("wxGISNetServerConnection: LOST"));
            {
                IPaddress addr;
                if (!m_pSock->GetPeer(addr))
                {
                    wxLogMessage(_("User #%d is disconnected"), m_nUserId);
                }
                else
                {
                    wxLogMessage(_("User #%d from %s:%d is disconnected"), m_nUserId, addr.IPAddress().c_str(), addr.Service());
                }

                m_bIsConnected = false;
                //send bye to the app
                wxNetMessage msgin(enumGISNetCmdBye, enumGISNetCmdStUnk, enumGISPriorityHigh);
                PostEvent(new wxGISNetEvent(m_nUserId, wxGISNET_MSG, msgin));

                //as connection is lost we destroy itself
                Destroy();
            }
            break;
        default:
            break;
    }
}
Esempio n. 26
0
void RMENet::HandleEvent(wxSocketEvent& evt)
{
	NetworkConnection* connection = reinterpret_cast<NetworkConnection*>(evt.GetClientData());
	switch(evt.GetSocketEvent())
	{
		case wxSOCKET_LOST:
		// Connection was lost, either client disconnecting, or our socket breaking
		{
			// Generate event
			wxCommandEvent event(EVT_RMENET_CONNECTION_LOST);
			event.SetInt(0);
			event.SetString("GOOOFU");
			event_dump->AddPendingEvent(event);
		} break;
		case wxSOCKET_OUTPUT:
		// We're ready to write to a socket
		{
			// Send waiting data
			connection->Send();
		} break;
		case wxSOCKET_INPUT:
		// We got some data to be read.
		{
			NetworkMessage* nmsg = connection->Receive();
			if(nmsg)
			{
				try
				{
					OnParsePacket(nmsg);
					FreeMessage(nmsg);
				}
				catch(std::runtime_error&)
				{
					FreeMessage(nmsg);
					Close();
				}
			}
		} break;
	}
}
Esempio n. 27
0
void PSocketServer::OnSocketEvent(wxSocketEvent &event)
{
    wxCharBuffer buf(32*1024);
    wxSocketBase *sock = event.GetSocket();
    switch (event.GetSocketEvent()) {
        case wxSOCKET_INPUT:
            sock->Read(buf.data(), 32*1024);
            sock->Write(buf, 32*1024);
            text->AppendText(buf);
            text->AppendText("\n");
//            sock->Destroy();
            break;
        case wxSOCKET_LOST:
            this->checkSocketStatus(sock);
            wxLogMessage("socket lost!");
            sock->Destroy();
            break;
            
        default:
            break;
    }
}
Esempio n. 28
0
void wxGISLocalNetworkPlugin::OnTCPServerEvent(wxSocketEvent& event)
{
    switch(event.GetSocketEvent())
    {
        case wxSOCKET_INPUT:
            wxLogError(_("wxGISLocalNetworkPlugin: Unexpected wxSOCKET_INPUT in wxSocketServer"));
            break;
        case wxSOCKET_OUTPUT:
            wxLogError(_("wxGISLocalNetworkPlugin: Unexpected wxSOCKET_OUTPUT in wxSocketServer"));
        break;
        case wxSOCKET_CONNECTION:
        {
            // Accept new connection if there is one in the pending
            // connections queue, else exit. We use Accept(false) for
            // non-blocking accept (although if we got here, there
            // should ALWAYS be a pending connection).

            wxSocketBase* sock = m_listeningSocket->Accept(false);
            IPaddress addr;
            if (!sock->GetPeer(addr))
            {
                wxLogError(_("wxGISLocalNetworkPlugin: cannot get peer info"));
            }
            else
            {
                wxLogMessage(_("wxGISLocalNetworkPlugin: Got connection from %s:%d"), addr.IPAddress().c_str(), addr.Service());
            }

            wxGISLocalServerConnection* pSrvConn = new wxGISLocalServerConnection();
            pSrvConn->SetSocket(sock);
            m_pNetService->AddConnection(pSrvConn);
        }
        break;
        case wxSOCKET_LOST:
            wxLogError(_("wxGISLocalNetworkPlugin: Unexpected wxSOCKET_LOST in wxSocketServer"));
        break;
    }
}
Esempio n. 29
0
void wxLuaDebuggerwxSocketServer::OnServerEvent(wxSocketEvent& event)
{
    switch(event.GetSocketEvent())
    {
        case wxSOCKET_CONNECTION:
        {
            wxSocketBase *sock = m_serverSocket->Accept(false);
            if (!sock)
            {
                // Error
                return;
            }

            sock->SetFlags(wxSOCKET_NOWAIT);
            m_acceptedSocket = new wxLuawxSocket(sock);
            m_acceptedSocket->m_port_number = m_port_number; // can't get it from wxSocketBase
            m_acceptedSocket->m_name = wxString::Format(wxT("wxLuaDebuggerwxSocketServer::m_acceptedSocket (%ld)"), (long)wxGetProcessId());

            // Setup Handler
            sock->SetEventHandler(*this, ID_WXLUA_SOCKET);
            sock->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
            sock->Notify(true);

            wxMilliSleep(500);

            // Notify that a client has connected and we are ready to debug
            wxLuaDebuggerEvent debugEvent(wxEVT_WXLUA_DEBUGGER_DEBUGGEE_CONNECTED, this);
            AddPendingEvent(debugEvent);

            break;
        }

        default:
            // Error
            break;
    }
}
Esempio n. 30
0
void ControlPanel::OnSocketEvent(wxSocketEvent& event)
{
	switch(event.GetSocketEvent())
	{
		case wxSOCKET_CONNECTION : 
			break;
		case wxSOCKET_LOST  : 
			wxLogMessage(_T("Connection to server lost!"));
			Connection(false);
			break;
		case wxSOCKET_INPUT: // gets only notifications
		{
			// We disable input events, so that the test doesn't trigger
			// wxSocketEvent again.
			m_pSocket->SetNotify(wxSOCKET_LOST_FLAG);
			
			// get data
			wxString msg = ReadFromSocket(m_pSocket);
			// translate it to notification
			Notification note = XMLUtils::xmlToNotification((const char*)msg.c_str());
			
			if(note.getName() == "CONNECTION_OK")
			{
				m_clientId = note.getOwnerID();
				m_bConnected = true;
				wxLogMessage(_T("Connected successfully to server with ClientID %d."), m_clientId);
			}
			else
				onNotification(note);
			// Enable input events again.
			m_pSocket->SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG);

			break;
		}
	}
}