Thread: Receive a TCP message on a UDP socket?

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

    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.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    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
    2,158
    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?

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    The answer is it cant. What makes you think it is sending you TCP data over a UDP socket?

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    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
    2,158
    Okay, separate connection. Thanks for the clarification.

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, 11:21 AM
  3. udp vs tcp.....
    By djarian in forum Networking/Device Communication
    Replies: 3
    Last Post: 12-15-2003, 11: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