Esempio n. 1
0
UDPSocketPair*  ProxySocketPool::ConstructUDPSocketPair()
{
    Assert(sProxyTask != NULL);
    //construct a pair of UDP sockets, the lower one for RTP data (outgoing only, no demuxer
    //necessary), and one for RTCP data (incoming, so definitely need a demuxer).
    //These are nonblocking sockets that DON'T receive events (we are going to poll for data)
    return NEW
        UDPSocketPair(  NEW UDPSocket(sProxyTask, UDPSocket::kWantsDemuxer | Socket::kNonBlockingSocketType),
                        NEW UDPSocket(sProxyTask, UDPSocket::kWantsDemuxer | Socket::kNonBlockingSocketType));
}
/* thread_socket_interface.cpp */

#include "thread_socket_interface.h"

UDPSocket receiver = UDPSocket();
string buf;
vector<string> vectbuf, vect1, vect2;
//hduMatrix t1, t2;
//hduMatrix r1, r2;
int i,j;

void parse(string buf, vector<string> &vect) {
    int front, back;
    // get data segment
    front = buf.find("HEAD") + 6;
    back = buf.find("TAIL", front);
    string data = buf.substr(front, back-front-1);
    
    boost::split(vect, data, boost::is_any_of(","));
}

void connectionInit() {
    // Initialize sockets
    if(!receiver.create())
        cout << "error creating server socket" << endl;
    if(!receiver.bind(RECEIVE_PORT))
        cout << "error binding to port " << RECEIVE_PORT << endl;
    //receiver.set_non_blocking(true);
    receiver.set_timeout(0);             // using recv()    
}
Esempio n. 3
0
void iphoneMainMenu() {	
	if ( !btnResumeGame.texture ) {
		// initial setup
		#ifdef IPAD
		SetButtonPics( &btnResumeGame, "iphone/resume_game.tga", "Resume Game", 216, 338 );
		SetButtonPics( &btnNewGame, "iphone/new_game.tga", "New Game", 446, 338 );
		SetButtonPics( &btnWWW, "iphone/website.tga",  "Website", 676, 338 );
		SetButtonPics( &btnMultiplayer, "iphone/multiplay.tga",  "Multiplayer", 347-17, 568 );
		SetButtonPics( &btnControls, "iphone/controls.tga", "Options", 545+17, 568 );	
		
		SetButtonPics( &btnLabel1, "iphone/label1.tga", "", 0,   20 );
		SetButtonPics( &btnLabel2, "iphone/label2.tga", "", 256, 20 );
		SetButtonPics( &btnLabel3, "iphone/label3.tga", "", 512, 20 );
		SetButtonPics( &btnLabel4, "iphone/label4.tga", "", 768, 20 );

		btnLabel1.buttonFlags = BF_INACTIVE;
		btnLabel2.buttonFlags = BF_INACTIVE;
		btnLabel3.buttonFlags = BF_INACTIVE;
		btnLabel4.buttonFlags = BF_INACTIVE;
		
		#else
		SetButtonPics( &btnResumeGame, "iphone/resume_game.tga", "Resume Game", 16, 4 );
		SetButtonPics( &btnNewGame, "iphone/new_game.tga", "New Game", 176, 4 );
		SetButtonPics( &btnDemo, "iphone/demo.tga", "Demos", 336, 4 );
		SetButtonPics( &btnMultiplayer, "iphone/multiplay.tga",  "Multiplayer", 16, 168 );
		SetButtonPics( &btnWWW, "iphone/website.tga",  "Website", 176, 168 );
		SetButtonPics( &btnControls, "iphone/controls.tga", "Options", 336, 168 );
		#endif
	}
		
		
	#ifdef IPAD
	HandleButton(&btnLabel1);
	HandleButton(&btnLabel2);
	HandleButton(&btnLabel3);
	HandleButton(&btnLabel4);
	#endif
	
	
	if ( netgame ) {
		// disable buttons if we are already in a netgame
		btnNewGame.buttonFlags = BF_INACTIVE | BF_TRANSPARENT;
		btnMultiplayer.buttonFlags = BF_INACTIVE | BF_TRANSPARENT;
		btnWWW.buttonFlags = BF_INACTIVE | BF_TRANSPARENT;
		#ifndef IPAD
		btnDemo.buttonFlags = BF_INACTIVE | BF_TRANSPARENT;
		#endif
	}

	if ( HandleButton( &btnResumeGame ) ) {
		ResumeGame();
	}

	if ( HandleButton( &btnNewGame ) ) {
		menuState = IPM_MAPS;
	}
		
	if ( HandleButton( &btnControls ) ) {
		menuState = IPM_CONTROLS;
	}
	
	if ( !NetworkAvailable() ) {
		// disable multiplayer if we don't have a good device
		//btnMultiplayer.buttonFlags = BF_INACTIVE | BF_TRANSPARENT;
		btnMultiplayer.buttonFlags = BF_TRANSPARENT;
	} else if ( netgame ) {
		// disable multiplayer if we are already in a netgame
		btnMultiplayer.buttonFlags = BF_INACTIVE | BF_TRANSPARENT;
	} else if ( NetworkServerAvailable() ) {
		// blink the multiplayer button if a local server is available
		btnMultiplayer.buttonFlags = BF_GLOW;
	} else {
		btnMultiplayer.buttonFlags = 0;
	}
	
	if ( HandleButton( &btnMultiplayer )) {
		if (NetworkAvailable()) {
			// get the address for the local service, which may
			// start up a bluetooth personal area network
			boolean serverResolved = ResolveNetworkServer( &netServer.address );
		
			// open our socket now that the network interfaces have been configured
			// Explicitly open on interface 1, which is en0.  If bluetooth ever starts
			// working better, we can handle multiple interfaces.
			if ( gameSocket <= 0 ) {
				gameSocket = UDPSocket( "en0", DOOM_PORT );
			}
		
			// get the address for the local service
			if ( !serverResolved ) {
				// nobody else is acting as a server, so start one here
				RegisterGameService();
				SetupEmptyNetGame();
			}		
			menuState = IPM_MULTIPLAYER;
		} else {
			SysShowAlert("Attention:", "Multiplayer requires a WiFi connection that doesn't block UDP port 14666");
		}
	}
	// draw the available interfaces over the blinking net button
	if ( NetworkServerAvailable() ) {
 		iphoneCenterText( btnMultiplayer.x + btnMultiplayer.drawWidth / 2, 
						 btnMultiplayer.y + btnMultiplayer.drawHeight/2, 0.75,
								 NetworkServerTransport() );
	}
	
	if ( HandleButton( &btnWWW ) ) {
//		menuState = IPM_PACKET_TEST;	// !@# debug
		SysIPhoneOpenURL( "http://doomsday.generalarcade.com/" );
		
	}
	#ifndef IPAD
	if ( HandleButton( &btnDemo ) ) {
		StartDemoGame( btnDemo.twoFingerPress );
	}
	
	if ( btnDemo.twoFingerPress ) {
		strcpy( timeDemoResultString, "TIMEDEMO" );
	}
	// draw the timedemo results on top of the button
	if ( timeDemoResultString[0] ) {
		iphoneCenterText( btnDemo.x + btnDemo.drawWidth / 2, btnDemo.y + btnDemo.drawHeight/2, 0.75,
						 timeDemoResultString );
	}
	#endif
}