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 8586569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:20:27+00:00 2026-06-11T22:20:27+00:00

/* SEND FUNC. */ int mysend(unsigned char *buffer, int len) { int sock,ret; int

  • 0
/* SEND FUNC. */
int mysend(unsigned char *buffer, int len) {

int     sock,ret;
int     status,flags;
struct sockaddr_in6 servaddr;
int opt = 1;
char *addr = "1101::1";

sock = socket(AF_INET6,SOCK_DGRAM,0);
if (sock < 0)
    return -1;
if( setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(opt)) < 0 ) 
    return -1;
flags = fcntl(sock, F_GETFL, 0);
fcntl(sock, F_SETFL, flags|O_NONBLOCK);

servaddr.sin6_family = AF_INET6;
servaddr.sin6_port = htons(61616);

status = inet_pton(AF_INET6, addr, &servaddr.sin6_addr);
if (status <= 0) {
    perror("inet_pton");
    return -1;
}
/* send message to server */
status = sendto(sock, buffer, len, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
if (status < 0) {
    perror("sendto");
    return -1;
}
close(sock);
printf("MESSAGE SENT SUCCESSFULLY\n");
return 0;
}

/* RECEIVE FUNC. */
int myrcv() {


int     sock,ret;
int     status,len,rx_bytes;
int timeout,nfds =1;
struct sockaddr_in6 servaddr;
struct timeval wait;
unsigned char rxbuff[1024];
char *rcv;
char *addr = "1101::1";
fd_set rd;
struct pollfd *fds;


sock = socket(AF_INET6,SOCK_DGRAM,0);
if (sock < 0) 
    return -1;

servaddr.sin6_family = AF_INET6;
servaddr.sin6_port = htons(61616);

status = inet_pton(AF_INET6, addr, &servaddr.sin6_addr);
if (status <= 0) 
    return -1;
bind(sock,(struct sockaddr *)&servaddr,sizeof(servaddr));
timeout = (1* 1000);

wait.tv_sec = 10;
wait.tv_usec = 0;

len = sizeof(servaddr);
fds->fd = sock;
fds->events = POLLIN;

for(;;) {
  //FD_ZERO(&rd);
  //FD_SET(sock,&rd);

    printf("Waiting for data....\n");
    ret = poll(fds,nfds,timeout);

  //ret = select(1,&rd,NULL,NULL,&wait);
    if(ret < 0)
        break;
    if(fds->revents == 0)
      printf("revents 0 %d\n",ret);

    if(ret == 0)
       continue;

    memset(rxbuff,0,1024);
   //if(FD_ISSET(sock,&rd)) {
        printf("receiving message\n");
        rx_bytes = recvfrom(sock,rxbuff,1024,0,(struct sockaddr *)&servaddr,&len);
        memcpy(rcv,rxbuff,rx_bytes);
  //}      
}
close(sock);
return 0;
}

int main()
{
/* call mysend() periodically using sigaction() */
/* create a thread that continuously monitors(calls myrcv()) for incoming data */
    return 0;
}

I’m unable to receive the packets from the server, but I could see the packets in the tcpdump output. Above are the sample client code snippets, which tries to receive and send the data from/to the server. The scenario is: the client needs to send data periodically to server and should also be able to receive any data from the server.
I have tried using both poll and select methods but failed to receive. Please let me know if I’m missing anything. Thanks for your support.

  • 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-06-11T22:20:28+00:00Added an answer on June 11, 2026 at 10:20 pm

    The problem you have with receiving is that you need to bind the receiving socket to the local port.

    You also have other things that can be improved, like creating a single socket for both sending and receiving and using SO_REUSEADDR on the sending socket (not needed on a write-only socket).

    What you should do is:

    1. Create socket
    2. Set socket options
    3. Bind to local address (Use IN6ADDR_ANY_INIT to bind to all interfaces)
    4. Write to server
    5. Poll for reply
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If i create a char a[100][100]; and send to a function void func(char** a);
My code : HotKeySet(^v,ClipboardToKeystroke) While 1 WEnd Func ClipboardToKeystroke() Send(ClipGet(),1) EndFunc Unfortunately it doesn't
Should be simple enough; I literally want to send an int to the a
The function header is defined below: /** * \fn int fx_add_buddylist(const char* name, EventListener
Below is how far I made it. I need to send Expression<Func<T, string>> as
to send a message in my application in android i have used the following
I send 2 bytes of app data on the socket(blocking) every 10 seconds, but
I send a query to an api and map the json results to my
I send to my sever this POST petition: name=pepito&friends=pep+mar And I notice what arrives
I send email through Outlook using VB.Net 2005; this is working fine. At the

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.