UDP Multicast Client Binding

hey -

i’m running into problems establishing a UDP connection for my client application. all calls made to udp.BindMcast(ipStr, portNum) return the error “can’t bind to port.”

i’m using the following settings:

multicast IP address:
portNum: 1267

i double checked to make sure that the firewall is disabled on my mac. What other factors should I be paying attention to? fyi, ofxUDPManager.Create() has also been called.

many thanks!


OSX 10.4.10

I could be totally wrong, but I think you will want to pick an address that’s proper for multicast, as I understand it (from wikipedia)

Multicast: A multicast address is associated with a group of interested receivers. According to RFC 3171, addresses to are designated as multicast addresses. This range was formerly called “Class D.” The sender sends a single datagram (from the sender’s unicast address) to the multicast address, and the routers take care of making copies and sending them to all receivers that have registered their interest in data from that sender.

  • zach

right on. it’s connecting now. i thought i’d need to set the ip address to a local one. thanks for pointing that out.


ok, the muticast setup is not working just yet, but i’m making some more headway.
i have both the client and server connecting properly.
fyi, on osx, in order to keep my applications from freezing, i needed to set the timeout for sending and receiving packets to 0.

on the server side, this was done by calling:


after udp.Create()

and on the client side:


unfortunately, the server isn’t sending any packets … i’m just getting lots o’ SOCKET_TIMEOUT errors.

still working away …


are you sure the server needs to have a timeout? I’d guess that for multicast, only the client would really need a timeout. The server should just send as much as it can as fast as it can. I can’t imagine a situation in which it could get blocked, but the client easily can get blocked if there is nothing to read, for example.

take care,

fyi - jeremy is working through the mac port of this:


which I just uploaded, it’s a pc demo of a non-threaded, completely easy to use mutlicast communication. we’ve recently used it for a project and it’s very flexible – clients can connect and disconnect and run if the server is not running, etc. I recommend it for mutli-computer rendering because you can work from one project, with one h file that defines a struct of data to be passed over… super happy to not use tcp and this system seems very flexible.

  • z

you’re probably right about that one, zach. my server application was freezing on startup, and i thought that was the right way to set the application so that it’s non-blocking.

it turns out that this is the correct way to do this:

int blocking = udp.SetNonBlocking(true);
if(!blocking) printf(“changing blocking state failed\n”);

i’ll post some code soon.


hey zach,

i was able to figure out what was keeping udp multicasting from working on a mac.

first of all, there was a timeout loop on the server sending side. based on our conversation, i wasn’t sure that this was necessary, so i commented it out.

int	ofxUDPManager::Send(const char* pBuff,	const int iSize)  
	if (m_hSocket == INVALID_SOCKET) return(SOCKET_ERROR);  
	if (m_dwTimeoutSend	!= NO_TIMEOUT)  
		fd_set fd= {1, m_hSocket};  
		timeval	tv=	{NULL, 0};  
		if(select(0, NULL, &fd,	NULL, &tv) == 0)  
	return (sendto(m_hSocket, (char*)pBuff,	iSize, 0, (sockaddr *)&saClient, sizeof(sockaddr)));  
	//return(send(m_hSocket, pBuff, iSize, 0));  

the other issue i was having was that the server could not connect if the client had already connected. diggiding into the code, i discovered that both the client and the server were trying to bind to the same port.

so in, connect multicast, i hardcoded the bind port to 0, which takes the first available port.

bool ofxUDPManager::ConnectMcast(char* pMcast, unsigned short usPort)  
	// associate the source socket's address with the socket  
	if (!Bind(0))  
#ifdef _DEBUG  
		printf("Binding socket failed! Error: %d", WSAGetLastError());  
		//printf("failed. failed. failed.\n");  
		return false;  
	// set ttl to default  
	if (!SetTTL(1))  
#ifdef _DEBUG  
		printf("SetTTL failed. Continue anyway. Error: %d", WSAGetLastError());  
	if (!Connect(pMcast, usPort))  
#ifdef _DEBUG  
		printf("Connecting socket failed! Error: %d", WSAGetLastError ());  
		return false;  
	// multicast connect successful  
	return true;  

i’m wondering if this will break anything on the pc-side. i’ll give it a shot this afternoon.