|
-
Jun 27th, 2002, 09:35 PM
#1
Thread Starter
Addicted Member
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?
-
Jun 27th, 2002, 10:51 PM
#2
PowerPoster
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.
-
Jun 27th, 2002, 11:09 PM
#3
PowerPoster
check out my sample code for both with Async and w/o Async
-
Jun 29th, 2002, 08:02 AM
#4
Thread Starter
Addicted Member
Thanks
int i;
SOCKET s[];
i=1;
s[i]=soceket(....) gives some lib error
How to create an array of socket?
-
Jun 29th, 2002, 01:51 PM
#5
PowerPoster
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.
-
May 29th, 2003, 09:35 PM
#6
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|