read from socket


 
Thread Tools Search this Thread
Top Forums Programming read from socket
# 1  
Old 07-14-2012
read from socket

hello

I have a C program and I want to read data from a socket ,and especially I want a client to send a .jpg to the server.The problem I face is that no matter what the size of the photo is,my read command seems to read an amount of data and then does nothing.

Code:
while(1){
   if(read(sockdes,&c,sizeof c)<=0){
       perror("read");
       break;
   }
}

The strange thing is that perror doesn't print anything,which means that read is successful,also I checked if I closed the socket in the server code,but I do not.
# 2  
Old 07-16-2012
what is 'c'?
# 3  
Old 07-16-2012
I am curious how you are sending the .jpg file? Are you first encoding it to base64 or any other encoding schemes and then sending the encoded data to the server and subsequently decode it?
# 4  
Old 07-17-2012
Quote:
Originally Posted by Corona688
what is 'c'?
...as in what is your variable 'c', there?
# 5  
Old 07-18-2012
Quote:
Originally Posted by vlm
hello

I have a C program and I want to read data from a socket ,and especially I want a client to send a .jpg to the server.The problem I face is that no matter what the size of the photo is,my read command seems to read an amount of data and then does nothing.

Code:
while(1){
   if(read(sockdes,&c,sizeof c)<=0){
       perror("read");
       break;
   }
}

The strange thing is that perror doesn't print anything,which means that read is successful,also I checked if I closed the socket in the server code,but I do not.
Your code says to read from the socket until an error is received. No data is not an error, so the read() call just blocks waiting for more data.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

Read() time out in socket programming

Hi, When can the read() system call gives timeout error when the same connection worked for writing data to the other end of the socket, while the next call with read() gives timeout error? Can anyone please explain when this kind of situation appears? Thanks, Sanzee (2 Replies)
Discussion started by: sanzee007
2 Replies

2. UNIX for Advanced & Expert Users

Fatal: Read from socket failed: Connection reset by peer [preauth]

Hello, I have recently updated my AIX machine from version 6.1.7.5 to 6.1.9.1 and i noticed that the errpt of the server is full of ssh messages like the one below: sshdprocess_id>]: fatal: Read from socket failed: Connection reset by peer Does anyone knows if this a known bug of the ssh... (15 Replies)
Discussion started by: omonoiatis9
15 Replies

3. Shell Programming and Scripting

Read and write to tcp socket

Hello all, I have a requirement to read and write to a tcp socket from an HP-UX shell script. I see a /dev/tcp character device on my servers: crw-rw-rw- 1 root root 72 0x00004f Mar 28 18:37 /dev/tcp So I believe this is what I should use. The problem is that all the... (2 Replies)
Discussion started by: lupin..the..3rd
2 Replies

4. IP Networking

Clarification - Setting socket options at the same time when socket is listening

I need clarification on whether it is okay to set socket options on a listening socket simultaneously when it is being used in an accept() call? Following is the scenario:- -- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
Discussion started by: jake24
2 Replies

5. UNIX for Dummies Questions & Answers

fatal: Read from socket failed: Connection reset by peer

I get this error when I log in through console: "fatal: Read from socket failed: Connection reset by peer". Can you tell me what this is and why it happens, and how to stop it? Thank you. (1 Reply)
Discussion started by: iamnew2solaris
1 Replies

6. Programming

socket function to read a webpage (socket.h)

Why does this socket function only read the first 1440 chars of the stream. Why not the whole stream ? I checked it with gdm and valgrind and everything seems correct... #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include... (3 Replies)
Discussion started by: cyler
3 Replies

7. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

Hi, I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime. To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
Discussion started by: chandrutiptur
0 Replies

8. Programming

command line socket read utility

HI I have a messaging s/w daemon(TIBCO rvrd) provided by vendor which will accept connections from various clients and routes messages to the destinations. In order to route it internally uses two ports(one tcp adn one udp). I want to know on which port(tcp/udp) it is transmitting... (3 Replies)
Discussion started by: axes
3 Replies

9. Programming

read/write socket error

I have client and server connected. client write and read from csock. server write and read from ssock suppose the server does : .... close(ssock); //send FIN to client othertask(); .... READ ERROR if after the server close() the client does: ... read(csock,...); ...... (2 Replies)
Discussion started by: gio
2 Replies

10. Programming

client socket read returns 0 bytes

Hi I have apeculiar problem with sockets. I have a shared object for my client program. when I send a request to the server, it is suppose to process and sends back the result string to the client. For the first request, it is working fine i.e. client sends the req. and gets the... (1 Reply)
Discussion started by: axes
1 Replies
Login or Register to Ask a Question