server with multiple clients

This is a discussion on server with multiple clients within the C Programming forums, part of the General Programming Boards category; hey Im writing a server that handles multiple clients, but im having problem with CreateThread, what should it do?? void ...

  1. #1
    Unregistered
    Guest

    server with multiple clients

    hey

    Im writing a server that handles multiple clients, but im having problem with CreateThread, what should it do??


    void main(void)
    {
    struct sockaddr_in sa;
    SOCKET ServSock, KliSock;
    WORD wVer;
    WSADATA wsaData;
    int id=0;

    wVer=MAKEWORD(2,2);
    WSAStartup(wVer, &wsaData);
    memset((void*)&sa, 0, sizeof(sockaddr_in));
    sa.sin_port=htons(1111);
    sa.sin_family=AF_INET;
    sa.sin_addr.s_addr = INADDR_ANY;
    ServSock=socket(PF_INET, SOCK_STREAM, 0);
    bind(ServSock, (const sockaddr*)&sa, sizeof(sockaddr_in));

    listen(ServSock, 1);

    while(1)
    {
    KliSock=accept(ServSock, 0, 0);
    CreateThread(NULL, 2000, Server, (LPVOID)ServSock, NULL, (LPDWORD)&id);
    }

    closesocket(ServSock);
    WSACleanup();
    }

    HANDLE CreateThread(LPSECURITY_ATTRIBUTES attr, DWORD size, LPSECURITY_ATTRIBUTES startadress, DWORD flagga, LPWORD id)
    {
    HANDLE h;

    /*??????*/

    return h;
    }

    DWORD WINAPI Server(LPVOID lpParameter)
    {
    char kommando;

    SOCKET s= (SOCKET)lpParameter;

    while(1)
    {
    RecvBuffer(s, &kommando, 1);

    switch(kommando)
    {
    /*something*/
    }

    }
    }

    plz help! /Anne

  2. #2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple clients to "internet" server
    By Zarniwoop in forum C Programming
    Replies: 2
    Last Post: 10-11-2008, 11:04 PM
  2. TCP Sockets: multiple clients - one server
    By Printisor in forum C Programming
    Replies: 4
    Last Post: 11-01-2007, 10:34 AM
  3. MISO Soup: Multiple Clients and one Server
    By doubleanti in forum Networking/Device Communication
    Replies: 2
    Last Post: 07-24-2007, 02:29 AM
  4. Socket Help - Multiple Clients
    By project95talon in forum C Programming
    Replies: 5
    Last Post: 11-17-2005, 01:51 AM
  5. Server with multiple clients
    By Thantos in forum Networking/Device Communication
    Replies: 20
    Last Post: 09-02-2003, 05:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21