UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » socket binary data recv or read

#1 2008-07-14 08:10 PM

mariano
Member
Registered: 2008-07-14
Posts: 2

Re: socket binary data recv or read

fd->socketFileDescriptor = socket (PF_INET, SOCK_STREAM, 0);
name.sin_family = AF_INET;
hostinfo = gethostbyname (argv[1]);
if (hostinfo == NULL) 
    return  1;
else
    name.sin_addr = *((struct in_addr *) hostinfo->h_addr);
name.sin_port = htons (39990);
if (connect (fd->socketFileDescriptor,(struct sockaddr *)&name, sizeof(struct sockaddr_in))== -1)
{
   perror ("connect");
   return  1;
}

Offline

#2 2008-07-14 09:35 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: socket binary data recv or read

recv() and read() always work on binary data, and all data is binary.

Offline

#3 2008-07-14 10:11 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: socket binary data recv or read

Yeah, I'm guessing your real problem is in how you're determining how much data
you think is in your buffer after read()/recv() returns...  Ie: I'm betting you're doing
something silly like strlen(), which only works on null-terminated text strings...  But,
your posted code isn't any help in determining what exactly you're doing, since you
never actually show your read()/recv() call, nor how you're determining the buffer
only has "5 chars" in it...  Your posted code is all totally unrelated to the issue...

Offline

  • Index
  • » C
  • » socket binary data recv or read

Board footer

Powered by FluxBB