Results 1 to 6 of 6

Thread: winsock

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163

    winsock

    I am making a simple chat program using winsock.

    if I don't use WSAAsyncSelect(.....) and just use
    d=connect(s,(struct sockaddr *)&a,sizeof(a));

    d gives 0 "No error" but I can send to server only I can't get data from server.

    but if I use

    WSAAsyncSelect(.....)
    d=connect(s,(struct sockaddr *)&a,sizeof(a));

    d gives error but it works and I can send and receive.

    So how to check wether connection has established or not?
    Purushottam

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Better way would be using WSAAsynkSelect() because it'll run in non-blocking mode. After you call this function and tell it the message you want to post, you will recieve a message FD_ACCEPT. This means you have been connected (if there's no error). Note that FD_ACCEPT is also sent when you're in listening mode and a clients requests a connecting so you'll have to know in which state you are (listening or connecting).
    If you don't use the above function (although there're better ways to do it) then your connecting will be in blocking mode and you'll have to check for any recieved data in a loop. This will prevent you from doing other stuff unless you have a multithreading application.
    Baaaaaaaaah

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    check out my sample code for both with Async and w/o Async

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163
    Thanks

    int i;
    SOCKET s[];

    i=1;

    s[i]=soceket(....) gives some lib error

    How to create an array of socket?
    Purushottam

  5. #5
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    int i;
    SOCKET s[20];
    i=1;
    s[i]=socket(....)


    That was just an example but you can use a vector to dynamically resize the array if you want unlimited sockets.
    Baaaaaaaaah

  6. #6
    Addicted Member Buy2easy.com's Avatar
    Join Date
    Jul 2002
    Posts
    200
    how about:

    typedef struct mysocket
    {
    SOCKET s;
    mysocket *psocket;
    }
    NEWSOCKET;

    then just line the sockets up in your own dynamic linked list.

    i do not know that much about sockets but this should be possible if sockets work in the same ways as other variables like the int or char variables.

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