read/write through udp socket

This is a discussion on read/write through udp socket within the Networking/Device Communication forums, part of the General Programming Boards category; I found this free source for sockets http://www.koders.com/cpp/fidA3ACF7B...8F07FEAD4.aspx It seems great except for a little problem Code: Socket sc; sc.UdpSender();//setup ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    722

    read/write through udp socket

    I found this free source for sockets
    http://www.koders.com/cpp/fidA3ACF7B...8F07FEAD4.aspx
    It seems great except for a little problem
    Code:
    Socket sc;
    sc.UdpSender();//setup socket for sending udp packets
    sc.UdpBind(5000);//setup socket for reading udp packets
    If I do this I get an assertion error from the class itself.
    My question, can a UDP socket both read and write stuff? or do I need seperate sockets for each function ?
    Last edited by xErath; 05-21-2005 at 07:35 PM.

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    No you can read and write from the same UDP socket.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    I'm developing to apps that comunicate through the udp socket. For now the sockets comunicate only in the localhost.
    if I bind a socket to a port X in one app, the other one isn't allowed to bind it's socket to port X.. at least I'm getting error, because I can't bind the second socket to the port...
    Is this a expected behaviour? how can surpass this ?

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    You can't bind() to the same port twice on a host. You can bind() and listen() to port X in one application, and in the other application, send data, but not bind(), to port X. In this scenario, one application is the server, and the other is the client. If you think about it, it doesn't make sense for the client to bind to any port because you don't care what port you send data on, but you do care what port the data arrives at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. UDP socket partial reading
    By mynickmynick in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-25-2009, 12:43 PM
  2. Can I bind a UDP socket to a port, but send to any other port?
    By trillianjedi in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-25-2009, 04:27 PM
  3. Error in creating socket in a client (UDP)
    By ferenczi in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-27-2008, 11:11 AM
  4. UDP Socket hangs when not available
    By MrLucky in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-23-2007, 11:53 AM
  5. problem with UDP WSAAsyncSelect socket, no callback message received???
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-29-2004, 11:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21