How to send image through ethernet(tcp/ip)?

HI,
i was working on a project in linux where tcp/ip communication is needed(i am using BSD sockets,calls like connect,send etc., ).
i send the data in the structure format. now i need to send an image, there comes the problem. i was new to this so can any one throw some light on how to send the image?
my guess were :
should i convert that Image into some binary data?? if so how can i do that?
or is there any way to send the image itself without any conversion?

Thnk in advance
@cpplinuxnewbie
should i convert that Image into some binary data?? if so how can i do that?

The image is already binary data.

Just send it.
The image is already binary data
ok..
How to send ?? i mean Can any one give me the BSD socket system call with parameters to send the image .
for example to send message we use send(ssize_t send(int s, const void *buf, size_t len, int flags);) system call ..
In the same manner so that i can send the image directly.

@@Thanx in advance
Last edited on
Mmm, it sould like you need a sockets tutorial.

I've seen this one recomended, but I'd recomend reading a book like Stevens or Comer.
http://beej.us/guide/bgnet/
I think you should read the image into a buffer using read, then write the buffer to a socket descriptor, that's all, system calls may be used are as follows:

socket, connect(if you use UDP in your program, this is not necessary), read, write

#define LEN 1024

int fd;
int sockfd;
ssize_t nbytes;

sockfd = socket(AF_INET,SOCK_STREAM,0);

char buf[LEN];

memset(buf,0, LEN+1);

fd = open("yourImage",O_RDONLY);

//connecting or listening
...
//read

while((nbytes = read(fd,buf,LEN))>0){
write(sockdes,buf,nbytes);
}
..................
@hittlle Thnk u .. i changed my design .. isntead of sending the image to the server.. i am trying to get the image from the client to server with FTP
Topic archived. No new replies allowed.