Link to home
Start Free TrialLog in
Avatar of zouying
zouying

asked on

How to use WinSock ?

I am a learner Winsock,got some questions in CAsyncSocket,
1) I derive my own class from CAsyncClass, I send data from ther server side, but the OnSend are never invoked, Why?
2) Could anybody show me the sequence when using CAsyncSocket? Say, in the serve side, If I want to send sth after receive sth, how to call?
Thanks so much.
ASKER CERTIFIED SOLUTION
Avatar of nil_dib
nil_dib

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zouying
zouying

ASKER

Nil_dib, thank you very much. But I still don't fully understand. In fact, I tried to send some data from Client to Server, but can't. So I asked why OnSend is never invoked, and what is the seqence when calling send or receive? So, could you pls show me how to send data from client to Server? Again, thanks.
mhhh,
I think you are on the wrong way with the "OnSend" method ...
the appropiate method is OnReceive which is called when data receives.
Ok, step by step (client):
1. create a socket object
   CSocket mySock;
   mySock.Create();
2. connect to server:
   mySock.Connect("myserver.domain.com", 1048);
   perhaps you should call mySock.AsyncSelect(FD_READ|FD_WRITE|FD_CONNECT|FD_CLOSE|FD_OOB|FD_ACCEPT)
3. now you can send data from client to server:
   mySock.Send("hello world", 11);
   (on the server side "OnReceive" is called to signal that data is received)

hpoe this makes it more clear.
You can also look at http://www.winsite.com/info/pc/win95/programr/socktst3.zip/downl.html
this is a complete socket client (with MFC source!).