Tuesday 15 June 2010

c++ - failed to listen and connect winsock2 -


I have written in your Windows socket is a problem with the code, the C + + using wxDev. The output of the code below is:

  start ...: compatible ...: created ...: binding work ...: can not hear ...: error connecting ... ::: Cleaned up :::  

I do not know why listen and connect failed.

Code

  void serverFrm:: Server (wxCommandEvent and amp; event) {socket soak soca; WSADATA wsadata; Socodra_e Sock adad; If (WSAtartup (Macward (2, 2), & amp; wsadata) == 0) {box-> Article text (_ (": starting ... \ n")); } If (Lobetty (wsadata.wVersion)> gt = 2) (box-& gt; attachment (_ ( "(compatible ... \ n"));} Sockh = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); if ( Sock! = SOCKET_ERROR) {box-& gt; attachment (_ ( "built ... \ n"));} (and box-& gt; attachment (_ ( ":: error connecting ... \ n "));} SockAddr.sin_family = AF_INET; SockAddr.sin_port = htons (6788); SockAddr.sin_addr.S_un.S_addr = inet_addr (" 127.0.0.1 "); if (backrest (Sok (Sokad * ( & sockAddr), Akarf (sockAddr))! = SOCKET_ERROR) {box-& AppendText (_ ( "binding work ... \ n"));} (and box-& gt; attachment (_ ( "binding error ... ... \ n "));} If (sukah, somexon)! = 0) (Box-> Article (_ ("(listen ... ... \ n"));} and (box-> Article text (_ (":: can not listen ... ... \" );} Int siz = sizeof (soke); if (accept (sok, reenter_account & lieutenant; sokrad *> (& amp; sockAddr), & siz)! = SOCKET_ERROR {box- & AppendText ( _ ("(Connected ... \ n"));} and (box-> Attachment (_ ("Error connecting ... ... \ n")); } Harbor (soak); If (wscllnp () == 0) box-> Article text (_ ("::: clear ::: \ n")); }  

  if (dry, sommaxone)! = 0) / code> 

Your conditional inquiry is backwards.

Read the document and for the love of your code properly Kahless Indent.


No comments:

Post a Comment