send() problem

send() problem

Post by Kuang-chun Che » Wed, 25 Jan 1995 09:45:57



Hi,

   The synopsis of send() is

      #include <sys/socket.h>
      int send(int s, const void *msg, int len, int flags);

in HP-UX.  Could somebody tell me what is the meaning of "const void *msg".
I try to send a long integer from client to server by the following command

      long int event;
      ...
      send(socketFD, &event, sizeof(event), 0);
      ...

But it can't work and I got the error message

      "error: Invalid argument"

What's wrong ??  Thanks a lot :)

    Kuang-chun Cheng

 
 
 

send() problem

Post by Andrew L. Sandov » Thu, 26 Jan 1995 02:08:38



>in HP-UX.  Could somebody tell me what is the meaning of "const void *msg".
>I try to send a long integer from client to server by the following command

>      long int event;
>      ...
>      send(socketFD, &event, sizeof(event), 0);
>      ...

>But it can't work and I got the error message

>      "error: Invalid argument"
>What's wrong ??  Thanks a lot :)
>    Kuang-chun Cheng


If the error message you are refering to is from the compilier, try
casting "event".  i.e.:

send(socketFD,(const void *)&event, sizeof(event),0);

That should work.  "const void *" usually means you can pass a pointer to
any data type, but, you should cast it.

Hope that helps.

-Andrew L. Sandoval

 
 
 

send() problem

Post by Madhav Kaka » Fri, 27 Jan 1995 05:13:24




>Hi,

      long int event;
>      ...
>      send(socketFD, &event, sizeof(event), 0);
>      ...

>But it can't work and I got the error message
>      "error: Invalid argument"
>    Kuang-chun Cheng


Send requires a character buffer of length len. The following example
illustrates this.
char* buf = "This is a message";
send(sockFd,buf,strlen(buf),0);
                                - madhav


 
 
 

send() problem

Post by Zachary Roadhou » Thu, 09 Feb 1995 10:32:23






> >Hi,
>       long int event;
> >      ...
> >      send(socketFD, &event, sizeof(event), 0);
> >      ...

> >But it can't work and I got the error message
> >      "error: Invalid argument"
> >    Kuang-chun Cheng

> Send requires a character buffer of length len. The following example
> illustrates this.
> char* buf = "This is a message";
> send(sockFd,buf,strlen(buf),0);
>                            - madhav



This is a nice example, but does not solve his problem.  I encountered this
problem not to long ago and resolved it with a few extra lines of code...

example:
       long event;
       char buf[sizeof(long)];

              memcpy(&event,buf,sizeof(event));
              send(socketFD,buf,sizeof(buf),0);

Remember that send is a specialized form of write (which you can use as
well)
Also remember to check the value returned by send or write to make sure all
your data was sent.  You might have to set up a loop to send all the data
in case it wasn't.  This strange behavior is a feature of the networking
code inside the OS.

               -- Zachary F. Roadhouse

WWW: http://www.netspace.org/~zack
***************************************************

 
 
 

send() problem

Post by Mark Ha » Fri, 10 Feb 1995 11:31:00


various people commented on this problem:

Quote:> >       long int event;
> > >      ...
> > >      send(socketFD, &event, sizeof(event), 0);
> > >      ...

> > >But it can't work and I got the error message
> > >      "error: Invalid argument"

suggesting copying it to a buffer, and passing that buffer to send.
this is RIDICULOUS!  folks, you _are_ smarter than the compiler,
sometimes at least and this is what casts are for: when the prototype
expects a char*, and it really _should_ be a void*, you need a cast:
        long event;
        send(socketFD, (char*) &event, sizeof(event), 0);

remember, send predates sensible typechecking in C (Ansi).  SunOS 4
and osf/1 seem to like the (broken) char* parameter, whereas hpux,
linux and irix have the more sensible:
      int send(int s, const void *msg, int len, int flags);

regards, mark hahn.
--

 
 
 

send() problem

Post by Dave Carn » Sun, 12 Feb 1995 11:45:25


Hey guys. You're making it far too difficult.
    send(fd, (char *) &event, sizeof(event), 0);

Don't copy. You'll kill the performance.  But note that on boxes where
the byte order might be differnet this won't be well received.
So maybe....
    long event, event2;
    event2 = htonl(event);
    send(fd, (char *) &event2, sizeof(event2), 0);

Dave

 
 
 

1. send() problem

Hi,

I have a problem with my UDP application using sockets.  I'm sending a
few Megabytes of data in chunks of 1k to a client socket, with send().
After some 10000 successful send()s in a row, something strange happens.
send() returns after 2 seconds, i.e. after a _very_ long time, with
return value 1k and no error code set.  _But_, no data arrives at the
client or is seen by a network tracer, and, from this first failure on,
all resend tries fail in the same way (send() needs two seconds to
return, no error code, no data is sent).

Does anyone know what the problem might be?

Thank you in advance,
  Stefan

2. Controlling updatedb and mounting

3. e-mail sending problems (not a newbie)

4. Mozilla fonts for MathML

5. pine send problems

6. NTLDR missing & SCO

7. > Suse 9.3, Hylafax, Sending Problems, fax machine rings once, then hangs up

8. RH 5.0 + WIN95: LI....and machine halts

9. send() problem : 0 bytes received by client

10. send problem

11. Dip send problem

12. ftp sending problem

13. Brust data send problem on gigabit NIC on Linux