Click here to Skip to main content
15,913,773 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I would like to know how to send and receive messages in C programming
a. is it really possible to send and receive images in C
b. i tried few codes but i am not even able to receive byte array of the images..
Posted
Comments
George Jonsson 2-Jan-15 1:10am    
Send and receive where?
Between two classes, two processes or two computers?
venkat28vk 2-Jan-15 1:36am    
hi
i am using tcp/ip programming, i think you must be aware of sending and receiving text between a server and client, similarly i have to send and receive images i hope this clarifies your doubt...
George Jonsson 2-Jan-15 1:40am    
I have no doubts, just questions.
I also cannot read your mind, hence the need for more info.
Are you using a socket?
venkat28vk 2-Jan-15 1:51am    
i am sorry for not specifying correctly... you are right i am using sockets to send and receive images. can this be achieved in the above
venkat28vk 2-Jan-15 4:02am    
Hi george thanks for the answer you have provided, do you have any idea how does it work in unix because i am not using windows, i am using ubuntu so you must be aware how the code differs to the various environment.... and i would be glad if you could provide a sample code for the above

1 solution

It should be no problem to send an image via sockets in C.
Here is a tutorial for how to use sockets on Windows: Winsock tutorial – Socket programming in C on windows[^]

An image, or any data stored as a file, can be seen as a stream of binary data.
Hence, you can easily read the contents of any file into a buffer and send and receive the buffer over TCP/IP.

Use fopen and fread on the sending side and on the receiving side fopen and fwrite.
There should be plenty of examples out there for how to read and write binary files.

[UPDATE]
As the OP has stated that Linux is used, I add some links for sockets on Linux as well.
Sockets Tutorial[^]
Socket programming in C on Linux – tutorial[^]
Networking and Socket programming tutorial in C[^]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 2-Jan-15 2:29am    
5ed.
—SA
George Jonsson 2-Jan-15 9:11am    
Thanks Sergey.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900