Thread: I am not able to connect to UDP port using following code.

  1. #1
    Registered User
    Join Date
    Jun 2009

    I am not able to connect to UDP port using following code.

    CAsyncSocket sock;
    CString myStr("");
    LPCTSTR spHostAddress;
    spHostAddress = myStr.GetBuffer(myStr.getLength());
    sock.create(125,SOCK_DGRAM,FD_CONNECT,spHostAddres s);

    I am getting this error "A successful AfxSocketInit must occur before using this API."

    ip as wel as port r perfect, but its not connecting, can u pls guide me, is there any problem in above code
    Reply With Quote Multi-Quote This Message Quick reply to this message
    Edit/Delete Message

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    RING 0
    Well it means literally what it says. Call that function first. Chances are though you are missing some step in using that class. Also most people discourage the MFC socket classes, I'd check out the winsock raw API. Also you can pass CString objects to API's requiring a LPCTSTR as it's (LPCTSTR) operator is overrode.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  2. Basic port scanner code .. pls help ???
    By intruder in forum C Programming
    Replies: 18
    Last Post: 03-13-2003, 08:47 AM
  3. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM
  4. Serial port read..can someone tell me..
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 06-27-2002, 08:21 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM