CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Mar 2010
    Posts
    6

    Multicast speed limits issue!!

    I recently made a very small test program, almost same as the example from msdn

    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    I change the source code a little bit, so that it will be multicast, and it keepsending data as soon as possible, and I will look at task manager to see how much network is utilized.

    If ip address is a multicast address, the program only uses 10% of the network bandwidth.
    While the program use almost 100% bandwidth, if the ip address is a unicast address.

    2 PC connected to a switch, both use a fixed ip address, (There is no rounter involved)

    I like to make multicast tranportation faster, so that my application can have better performance. I wonder if there is any setting in windows or somewhere else for making multicast fast, or there is any function for the multicast socket.

    Please please help.
    Code:
    #ifndef UNICODE
    #define UNICODE
    #endif
    
    #define WIN32_LEAN_AND_MEAN
    
    #include <winsock2.h>
    #include <Ws2tcpip.h>
    #include <stdio.h>
    
    // Link with ws2_32.lib
    #pragma comment(lib, "Ws2_32.lib")
    
    int main()
    {
    
    	int iResult;
    	WSADATA wsaData;
    
    	SOCKET SendSocket = INVALID_SOCKET;
    	sockaddr_in RecvAddr;
    
    	unsigned short Port = 27015;
    
    	char SendBuf[1024];
    	int BufLen = 1024;
    
    	//----------------------
    	// Initialize Winsock
    	iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
    	if (iResult != NO_ERROR) {
    		wprintf(L"WSAStartup failed with error: %d\n", iResult);
    		return 1;
    	}
    
    	//---------------------------------------------
    	// Create a socket for sending data
    	SendSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    	if (SendSocket == INVALID_SOCKET) {
    		wprintf(L"socket failed with error: %ld\n", WSAGetLastError());
    		WSACleanup();
    		return 1;
    	}
    	//---------------------------------------------
    	// Set up the RecvAddr structure with the IP address of
    	// the receiver (in this example case "192.168.1.1")
    	// and the specified port number.
    	RecvAddr.sin_family = AF_INET;
    	RecvAddr.sin_port = htons(Port);
    	RecvAddr.sin_addr.s_addr = inet_addr("234.10.10.10");
    
    	//---------------------------------------------
    	// Send a datagram to the receiver
    	char ttl = 0;
    	int r = setsockopt(SendSocket, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));
    	wprintf(L"Sending a datagram to the receiver...\n");
    	while (true) {
    		iResult = sendto(SendSocket,
    			SendBuf, BufLen, 0, (SOCKADDR *)& RecvAddr, sizeof(RecvAddr));
    		if (iResult == SOCKET_ERROR) {
    			wprintf(L"sendto failed with error: %d\n", WSAGetLastError());
    			closesocket(SendSocket);
    			WSACleanup();
    			return 1;
    		}
    	}
    	//---------------------------------------------
    	// When the application is finished sending, close the socket.
    	wprintf(L"Finished sending. Closing socket.\n");
    	iResult = closesocket(SendSocket);	
    	if (iResult == SOCKET_ERROR) {
    		wprintf(L"closesocket failed with error: %d\n", WSAGetLastError());
    		WSACleanup();
    		return 1;
    	}
    	//---------------------------------------------
    	// Clean up and quit.
    	wprintf(L"Exiting.\n");
    	WSACleanup();
    	return 0;
    }
    Last edited by chiyuwang; September 9th, 2015 at 02:53 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured