Receive a TCP message on a UDP socket?

This is a discussion on Receive a TCP message on a UDP socket? within the C++ Programming forums, part of the General Programming Boards category; My program currently opens a UDP socket, and sends out a UDP message with it (naturally). It then receives a ...

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,591

    Receive a TCP message on a UDP socket?

    My program currently opens a UDP socket, and sends out a UDP message with it (naturally). It then receives a UDP message back. All is good. But every now and then, the remote computer will send back some TCP data to me, and completely forget UDP. How should I set up my socket to receive data in either protocol? Also, if I don't know what protocol the incoming data is being sent with, then how do I know if I received all of it? (UDP only sends one message, but TCP will send an unknown multiple amount)
    Last edited by Yarin; 09-04-2009 at 01:30 PM.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    This sounds more like a protocol problem. Why would some networking client send you UDP sometimes, and then randomly send you a TCP response instead? How can it even send you a TCP response if you didn't initiate a connection to it (or it didn't initiate a connection to you)?
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,591
    Quote Originally Posted by bithub View Post
    This sounds more like a protocol problem. Why would some networking client send you UDP sometimes, and then randomly send you a TCP response instead?
    Dunno - it's the DNS protocol, so I have to live with it if you know what I mean.
    Quote Originally Posted by bithub View Post
    How can it even send you a TCP response if you didn't initiate a connection to it (or it didn't initiate a connection to you)?
    That's exactly what I'm trying to figure out.

    Any ideas?
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    The answer is it cant. What makes you think it is sending you TCP data over a UDP socket?
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,643
    If you open a UDP socket, all you're going to get is UDP. There is no way that you'll get TCP responses back. DNS does allow both UDP and TCP communications, but in either case the client will make a separate connection (usually on port 53) using the appropriate protocol. Obviously then, your server will need to be listening for (eg: accept()) connections for both protocols 'simultaneously' (from two separate threads or via an asyncronous API).

  6. #6
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,591
    Okay, separate connection. Thanks for the clarification.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. UDP socket no longer works when put in to a class
    By System_159 in forum Networking/Device Communication
    Replies: 0
    Last Post: 04-08-2009, 07:55 AM
  2. UDP and TCP packets on port 6112
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 01-19-2004, 10:21 AM
  3. udp vs tcp.....
    By djarian in forum Networking/Device Communication
    Replies: 3
    Last Post: 12-15-2003, 10:41 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. TCP client/server problem.
    By WL in forum C Programming
    Replies: 0
    Last Post: 10-15-2001, 12:55 AM

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