Click here to Skip to main content
15,913,944 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Mid life crisis Pin
Chambers3-Dec-01 0:59
Chambers3-Dec-01 0:59 
GeneralRe: Mid life crisis Pin
Christian Graus3-Dec-01 11:50
protectorChristian Graus3-Dec-01 11:50 
GeneralRe: Mid life crisis Pin
Chambers4-Dec-01 4:26
Chambers4-Dec-01 4:26 
GeneralRe: Mid life crisis Pin
Erik Funkenbusch3-Dec-01 9:16
Erik Funkenbusch3-Dec-01 9:16 
GeneralRe: Mid life crisis Pin
3-Dec-01 11:21
suss3-Dec-01 11:21 
GeneralProgram design Pin
Steve P2-Dec-01 13:01
Steve P2-Dec-01 13:01 
GeneralBasic UDP Connection Pin
2-Dec-01 10:13
suss2-Dec-01 10:13 
GeneralRe: Basic UDP Connection Pin
Jon Sagara2-Dec-01 10:36
Jon Sagara2-Dec-01 10:36 
This function doesn't do exactly what you're looking for, but it's pretty close. You just have to change it so that the socket binds to a specific port instead of the next available port.

// ----------------------------------------------------------------------------
// udp_recv_setup()
//
// This function sets the server socket.  It lets the system determine the port 
// number.  The function returns the server socket number.
// ----------------------------------------------------------------------------
//
int udp_recv_setup()
{
	struct sockaddr_in local;			// socket address for local side 
	int nLocalAddrLen = sizeof(local);	// length of local address
	int nServerSocket = 0;

	//
	// Create the socket.
	//
	nServerSocket = socket(AF_INET, SOCK_DGRAM, 0);

	if ( nServerSocket < 0)
    {
		cout << "%error opening datagram socket \n" ;
		exit(1);
    }

	//
	// Bind the socket to a port, let the system decide the number.
	//
	local.sin_family		= AF_INET;		// Internet family
	local.sin_addr.s_addr	= INADDR_ANY;	// Wild card machine address  (defaults to local)
	local.sin_port			= 0;			// Let system choose the port 

	bind(nServerSocket, (struct sockaddr *) &local,sizeof(local));	//bind the name (address) to a port

	//
	// Get the port name and print it out.
	//
	getsockname( nServerSocket, (struct sockaddr *) &local, &nLocalAddrLen);		
	cout << "socket has port " << local.sin_port << endl;

	return  nServerSocket;
}


Jon Sagara

"Ninety percent of baseball is mental, the other half is physical." -- Yogi Bera
GeneralRe: TCP & UDP! Pin
Masaaki Onishi2-Dec-01 12:59
Masaaki Onishi2-Dec-01 12:59 
GeneralRe: TCP & UDP! Pin
Jon Sagara2-Dec-01 13:53
Jon Sagara2-Dec-01 13:53 
GeneralRe: Basic UDP Connection Pin
Jon Sagara2-Dec-01 10:50
Jon Sagara2-Dec-01 10:50 
GeneralRetrieving dialog box values Pin
2-Dec-01 7:24
suss2-Dec-01 7:24 
GeneralRe: Retrieving dialog box values Pin
Igor Sukhov2-Dec-01 12:48
Igor Sukhov2-Dec-01 12:48 
Generaltoolbar buttons problem Pin
2-Dec-01 6:09
suss2-Dec-01 6:09 
GeneralRe: toolbar buttons problem Pin
Igor Sukhov2-Dec-01 6:11
Igor Sukhov2-Dec-01 6:11 
GeneralRe: toolbar buttons problem Pin
2-Dec-01 15:27
suss2-Dec-01 15:27 
GeneralSetProcessWorkingSetSize AND Background Processes Pin
John M. Drescher2-Dec-01 6:05
John M. Drescher2-Dec-01 6:05 
GeneralRe: SetProcessWorkingSetSize AND Background Processes Pin
Gert Boddaert2-Dec-01 7:36
Gert Boddaert2-Dec-01 7:36 
GeneralRe: SetProcessWorkingSetSize AND Background Processes Pin
John M. Drescher2-Dec-01 8:07
John M. Drescher2-Dec-01 8:07 
GeneralRe: SetProcessWorkingSetSize AND Background Processes Pin
Tim Smith2-Dec-01 8:37
Tim Smith2-Dec-01 8:37 
GeneralRe: SetProcessWorkingSetSize AND Background Processes Pin
John M. Drescher2-Dec-01 17:01
John M. Drescher2-Dec-01 17:01 
GeneralRe: SetProcessWorkingSetSize AND Background Processes Pin
John M. Drescher3-Dec-01 6:21
John M. Drescher3-Dec-01 6:21 
Generalproblem with socket Pin
Fumiseki2-Dec-01 4:59
Fumiseki2-Dec-01 4:59 
GeneralRe: problem with socket Pin
markkuk3-Dec-01 1:52
markkuk3-Dec-01 1:52 
GeneralChanging bitmap of single toolbar button Pin
Erik Hammar2-Dec-01 2:06
Erik Hammar2-Dec-01 2:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.