CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: UDP connection

  1. #1
    Join Date
    Feb 2009

    Unhappy UDP connection

    hello group,
    i'm trying to send a socket over udp. i'm doing it on same machine with loopback address. i wrote a server code n a client code. when i run them both, there should be a connection when i send text from client to server. client window shows sent complete n server window says waiting for connection that means recvfrom() is hanged or blocked. it does not go beyond recvfrom(). i tried connect() also from client. no luck.
    my pseudo code is,

    create server socket
    create client socket
    s = socket(AF_INET, SOCK_DGRAM, 0);
    bind() //client socket


    creat server socket
    s= socket()
    "waiting for connection"

    please tell wer am i doing wrong.
    n one more,
    i have such a code for TCp also. it works fine with loopback addr. two windows on same machine talk to each other. but it does not work with network addr. like if i replace with it gives error.

  2. #2
    Join Date
    Aug 2007
    Birmingham, UK

    Re: UDP connection

    In the snippets of code you posted I spotted a few things -

    - Your client does not need to call bind().
    - You do not need to create a new socket for every UDP packet you send.
    - In the client loop you create loads of sockets, but never close them.
    - You create a socket for your server but do not specify what kind of socket you want to create? I don't think that even compiles?
    - You do not check any of the functions you call for errors.

    Therefore I do not think you posted the actual code - you just quickly made something up for your post. Could you please post the real code (and use code tags!) so that we can see what is really going on?

    Please note that there is no such thing as a "connection" for UDP. This is not just a semantics thing - it defines the way UDP behaves and all the ramifications that come with it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)