Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7510109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:07:54+00:00 2026-05-29T23:07:54+00:00

I have received data from UDP socket fd . How can I use this

  • 0

I have received data from UDP socket fd. How can I use this information to establish a TCP connection from the sender. buf contains the TCP port.

struct sockaddr_storage remote_addr;
socklen_t remote_addr_len;

recvfrom(fd, buf, BUFSIZE, 0, (struct sockaddr *)&remote_addr, &remote_addr_len);

The code below is my attempt, but it doesn’t work. I am new to socket programming and I am tearing my hair over trying to figure this out.

newfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
struct hostent *info;
info = gethostbyname(remoteAddr.h_addr);

struct sockaddr_in newConn;
newConn.sin_family = AF_INET;
bcopy((char *)info->h_addr, (char *)&newConn.sin_addr.s_addr, info->h_length);
newConn.sin_port = htons(mesgTcpPort); //mesgTcpPort is of type int gotten from buf


connect(newfd,(struct sockaddr *)&newConn,sizeof newConn);

Error checking is omitted.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:07:57+00:00Added an answer on May 29, 2026 at 11:07 pm

    You shouldn’t need gethostbyname, since the UDP packet contains an IP address, not a name, in its header (and given to you by recvfrom).

    However, this approach has limited applicability, since the new connection won’t traverse NAT because it won’t be associated with the original UDP connection, since the protocol and port differ.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Wordpress, PHP, jQuery and AJAX. I can get data from PHP through
I have a Java program that is constantly being sent UDP data from an
I have this TCP server running Because UDP server was able to accept large
i have a program that receives data from a wireless device over bluetooth...i now
I have a c++/windows program that receives data from another c++ program via a
I have developed a python C-extension that receives data from python and compute some
I have a user interface in .net which needs to receive data from a
I have a little logging app (written in wxPython) that receives data from a
We need to get data out of an older accounting system. We have received
I have an iPad app that receives data using UDP sockets. And it has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.