Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Mon, 24 Mar 2008 18:20:01 -0700,    group: microsoft.public.win32.programmer.directx.networking        back       


Socket and Multithreading   
Hello,

I'm working on creating a multi-player racing game and my server is 
multi-threaded and can send 5 packets/second over the network. I created a 
non-multithreaded server which used blocking and that was doing almost 50 
packets/second. This tells me something happened when I introduced threads. I 
even tried setting the priority to highest but no performance difference :

This is how I crate my thread :

for (;;) /* Run forever */
    {
       clntSock = AcceptTCPConnection(servSock);

        /* Create separate memory for client argument */
        threadArgs = (struct ThreadArgs *) malloc(sizeof(struct ThreadArgs));
        threadArgs -> clntSock = clntSock;
		threadArgs -> servSock = servSock;
		threadArgs -> clntAddr = getClientAddr();

        if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) ThreadMain, 
threadArgs, 
              0, (LPDWORD) &threadID) == NULL)
            DieWithError("pthread_create() failed");
        printf("with thread %ld\n", threadID);

    }
    /* NOT REACHED */
}

void *ThreadMain(void *threadArgs)
{
    SOCKET clntSock;                   /* Socket descriptor for client 
connection */
	SOCKET servSock;
	sockaddr clntAddr;

    /* Guarantees that thread resources are deallocated upon return */

    /* Extract socket file descriptor from argument */
    clntSock = ((struct ThreadArgs *) threadArgs) -> clntSock;
	servSock = ((struct ThreadArgs *) threadArgs) -> servSock;
	clntAddr = ((struct ThreadArgs *) threadArgs) -> clntAddr;

    free(threadArgs);              /* Deallocate memory for argument */
	

	/* Handle the clients */
    HandleTCPClient();

    return (NULL);
}

I'm new to threading and don't have much experience any code examples or 
please someone let me know what can be changed.

OS : Win Xp
Visual Studio 2008 Compiler

Please let me know if any other information is required.
date: Mon, 24 Mar 2008 18:20:01 -0700   author:   Harsimrat

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us