Thread: Simple Sockets problem...

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question Simple Sockets problem...

    I am creating a sockets program using Asynchronous sockets. Here's my problem. I do this:

    WSAAsyncSelect(sockfd, hwnd, MY_MSG, FD_READ);

    and I do:


    WORD version=MAKEWORD(1, 1);
    WSADATA data;

    WSAStartup(version, &data);

    And my program freezes and I have to do CTRL + ALT + DEL to end it. What do I do to stop this?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    Could you provide a little bit more code? Are you calling those in that order?
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Arrow Here...

    WORD version=MAKEWORD(1, 1);
    WSADATA data;

    WSAAsyncSelect(sockfd, hwnd, MY_MSG, FD_READ);

    switch (message) /* handle the messages */
    {
    case WM_CREATE:
    WSAStartup(version, &data);

    szRecvInfo=CreateWindowEx(
    WS_EX_STATICEDGE,
    "EDIT",
    "",
    ES_READONLY | ES_MULTILINE | WS_VSCROLL | WS_CHILD | WS_VISIBLE,
    0,0,
    400,200,
    hwnd,
    0,
    hInst,
    NULL
    );

    sockfd=socket(AF_INET, SOCK_STREAM, 0);

    my_addr.sin_family=AF_INET;
    my_addr.sin_port=htons(LSNPORT);
    my_addr.sin_addr.s_addr=INADDR_ANY;

    incoming=bind(sockfd, (LPSOCKADDR)&my_addr, sizeof(struct sockaddr));

    incoming=listen(sockfd, 2);

    .
    . //Some code
    .


    case MY_MSG:
    switch (WSAGETSELECTEVENT(lParam)) {
    case FD_READ:
    incoming=recv(con, szUsr, sizeof(szUsr), 0);

    SetWindowText(szRecvInfo, szUsr);

    GetWindowText(szRecvInfo, szInfo, 1000);

    WSACleanup();
    break;
    }
    break;
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Client - Server problems (Async Sockets )
    By Cpp_Noob in forum Networking/Device Communication
    Replies: 4
    Last Post: 06-19-2009, 07:12 AM
  2. Simple File I/O problem
    By Ignited in forum C++ Programming
    Replies: 3
    Last Post: 01-07-2006, 10:49 AM
  3. Fairly simple problem
    By fatdunky in forum C Programming
    Replies: 1
    Last Post: 11-14-2005, 11:34 PM
  4. Simple Variable Problem
    By Cthulhu in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2005, 04:07 PM
  5. Problem with Raw Sockets
    By Encrypted in forum Linux Programming
    Replies: 2
    Last Post: 04-30-2003, 04:38 PM