the connect function returns 0. I dont know why . I pass to it a legitimate IP and port#, so what else can be wrong or missing?
Dmitriy
August 14th, 1999, 06:02 PM
Yes, I see. Did you receive event OnAccept() on the server side? Did you create new socket on the server side in case you've received OnAccept()?
Dmitriy, MCSE
Vicken Simonian
August 14th, 1999, 06:06 PM
No, OnAccept doesnt even get called at all. In my OnAccept i did not create a new socket yet. i just created created a messagebox to notify my if it got called. the messagebox doesnt popup.
Dmitriy
August 14th, 1999, 06:33 PM
It seems to me, the message does not reach your server. Try ping your ip-address on the server.
Another question - why did you select port 700?
Try 21, for example.
Dmitriy, MCSE
Vicken Simonian
August 14th, 1999, 10:08 PM
Hello, i really appreciate you helping me out.
I pinged my ip and it pinged back, and i selected port 21 and it still didnt work.
I want to add that i already tried doing this with CSocket instead of CAsyncSocket:
This code works and my server pops a message box with the string "Send to the server". But the problem with this is that the server stops everything until the client sends its message. (I read that this is called blocking i think) So, i want the server to still be free to do its business and i heard i could do that with CAsyncSocket. But i try to do that with the code in my previous messages but Asyncsocket does not work right and i dont know what im doing wrong?
Paul Belikian
August 15th, 1999, 12:12 AM
Hi,
use GetLastError( ) and find the reason why the connect failed. Listen can only be used for TCP Stream connections, so please show us the Create function you used and possibly the AsyncSelect functions too. Your server also needs to Bind..."Before it can accept connection requests, a listening server socket must select a port number and make it known to Windows Sockets by calling Bind. Bind establishes the local association (host address/port number) of the socket by assigning a local name to an unnamed socket." I don't see that call in your code.
Vicken, Paul...
Regards,
Paul Belikian
Vicken Simonian
August 15th, 1999, 02:47 AM
Hello,
I did what you said and now i have the following:
Now, it still doesnt work. The GetLastError() function returns the value of 10035. Any idea what this is? Any other ideas?
Thanks for your time
Dmitriy
August 15th, 1999, 07:14 AM
I'm not sure, but try connectionless UDP-
in server socket.Create(700,SOCK_DGRAM)
Dmitriy, MCSE
Orion Mazzor
August 15th, 1999, 04:59 PM
I don't bother with the windows socket stuff, opting instead for using a more direct approach. A good example can be found in http://www.codeguru.com/network/ChessServer.shtml.
I did notice a couple possible problems. You don't do a call to WSAStartup(), Bind(), or Accept() on the server side. (Note, that the WSAStartup might be done in the CASyncSocket. Don't know, haven't used them.) The following snippet should give you an idea. (This example uses blocking sockets.) Hope it helps.
//SERVER STARTUP FUNCTION
//DON'T FORGET TO TEST FOR ERRORS
#define BACKLOG 5 //5 other client connections can pool up before getting an error
LPCSOCKADDR psa; //pointer to socket address you created before you called this
WSADATA wsd;
HSOCKET hsockListen; //your server socket
HSOCKET hsockNewConnection; //someone connecting with client program
WSAStartup(0x0101,&wsd);
hsockListen = socket(AF_INET, SOCK_STREAM, 0);
bind(hsockListen, psa, sizeof(SOCKADDR));
listen(hsockListen, BACKLOG);
hsockNew = accept(hsockListen, psa, &nLengthAddr);
//server is now waiting for a connection after the call to accept
kktoh
August 15th, 1999, 05:40 PM
MSDN does not tell you this but...the way that you should do this to to inherit the CAsyncSocket.
On the Client side, call the Create and Connect of the CAsyncSocket from your class. Make use of the Notification Functions (eg OnConnect) to determine if a successful connection has been established. The OnReceive Notification Function can be used to handle data received by the socket.
The server side is more tricky. You will need 2 classes...both which inherits the CAsyncSocket. One is used to handle the connection (eg. Create, Listen, Accept). Once the connection is about to be established, (detected using the OnAccept Notification Function), dynamically allocate your second class and call Accept from this class to accept the connection. When connection is established, handle the socket receive/transimit in this second class. Don't forget to use the notification function to receive and send your data through the socket.
kktoh
Software Engineer(BE Hons)
Paul Belikian
August 16th, 1999, 01:28 AM
Hi Vicken
The return value of 10035 is WSAEWOULDBLOCK. The result is simply saying that this call will cause a blocking action to take place. If you think about it, that's true. Until the connection is made, the connect function will block. The result codes are in winsock.h in the include directory of VC. OK, now you know why connect is 'failing', so Look up 'Connect' in the online help. Connect for the platform SDK, not the socket classes, because the classes are based on the raw socket functions.
Here is a partial listing from the help file...
On a blocking socket, the return value indicates success or failure of the connection attempt. With a nonblocking socket, the connection attempt cannot be completed immediately. In this case, connect will return SOCKET_ERROR, and WSAGetLastError will return WSAEWOULDBLOCK. In this case, there are three possible scenarios:
Use the select function to determine the completion of the connection request by checking to see if the socket is writeable.
If the application is using WSAAsyncSelect to indicate interest in connection events, then the application will receive an FD_CONNECT notification indicating that the connect operation is complete (successfully or not).
If the application is using WSAEventSelect to indicate interest in connection events, then the associated event object will be signaled indicating that the connect operation is complete (successfully or not).
I would use the WSAAsyncSelect function to get a message when the socket has actually connected. It's better to be notified when the connection happens than to have you application 'lock up' while waiting for it...this is the Windows Way. In the socket classes, WSAAsyncSelect is called AsyncSelect.
Regards,
Paul Belikian
srinivas a
August 16th, 1999, 02:33 AM
In create you specify all the options like
FD_READ | FD_WRITE | FD_ACCEPT | FD_CONNECT | FD_CLOSE | FD_CONNECT
also check whether that port is in use by any other program.
after listen you need call accept continously to accept client connections.
in the code you have given it seems you are not using it.
scottd
August 17th, 1999, 01:00 PM
Getting 0 from your Connect is a good sign - that means it succeeded!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.