problem with socket reading


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users problem with socket reading
# 1  
Old 05-20-2008
problem with socket reading

I am not able to receive the message on socket in the current process when its waiting for its child to exit.

code looks something like below
//in one thread of the current process
//thread 1

===============================================
int numBytes = read(sockid,buf,SIZE); //Now the thread is blocked
================================================


//in another thread
//thread 2

=================================================
if((pid = fork()) == 0) // child process
{
exec(...);
}
else
{
waitpid(pid); //now the process is blocked for the child's exit
}
=================================================
In the above scenario, when child is executing and parent is blocked for child's exit, also when there is some message available on the socket descrtiptor for the first thread to read, I am not able to read that even after child's exit. so could somebody throw more light on the above scenario?

Thanks in advance
Swap007
# 2  
Old 05-20-2008
Can you not use non-blocking reads or select()?
# 3  
Old 05-21-2008
yaaa I m using select call b4 doing read on socket .
so the code is somewhat like this

//thread 1

==========================================
int retval = select(.....)//Now the thread is blocked and it will be awaked whn something is thr to read from socket.


if(retval == -1)
cout<<"error"<<endl;
else
int numBytes = read(sockid,buf,SIZE);
============================================

is dis fine ????
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

Execution Problem with socket

Hi My socket program is to communicate between the two systems connected with lan. Always i am getting an error saying bind value is -1 or not connected. ..If i run both the server and client programs in the same machine in two diff terminals they are working but they are not working between two... (3 Replies)
Discussion started by: Gurvareddy
3 Replies

2. UNIX for Dummies Questions & Answers

"error reading on socket (104)"

Hi Guys, Can anyone explain to me what might be the possible cause on why I'm getting this error from our client server. Appreciate any input. Thanks! Br, rymnd_12345 (0 Replies)
Discussion started by: rymnd_12345
0 Replies

3. UNIX for Advanced & Expert Users

ssh error: Error reading response length from authentication socket

Hi - I am getting the error `Error reading response length from authentication socket' when I ssh from my cluster to another cluster, and then back to my cluster. It doesn't seem to affect anything, but it's just annoying that it always pops up and tends to confuse new users of the cluster. I... (1 Reply)
Discussion started by: cpp6f
1 Replies

4. Programming

Socket++ library problem.

Hi, My name is Daniel and I'm spanish, so I'm sorry if you can't undertand something becouse of my low-level english. Something stranger is happening to me with socket++ library and I don't know how to work on it. I has a library called commands.so and the sslclient is and object of that... (4 Replies)
Discussion started by: lock.cda
4 Replies

5. Programming

Problem with socket connection

I have a client /server file operation program.It works properly when i run the client and server program in the same system.but when i try to run the client in one system and server in another system i am getting an error in the cleint machine as "ERROR:Connection refused". Plz help me in this ... (1 Reply)
Discussion started by: vigneshinbox
1 Replies

6. 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

7. Programming

and again, socket() related problem...

Dear All, I've searched many topics and googled many web-pages, but still I didn't found solution to this problem. I want to set timeout for connect(). The thing is, that my code works only on BSD, on Linux (tested on SuSE box) it freezes at connect() call :( bool SomeFunc(std::string... (1 Reply)
Discussion started by: sggkxv
1 Replies

8. Programming

unable to get end of file while reading HTTP data from socket

I am trying to read HTTP data from a socket. However, for the final set of data being read using read(), read blocks and the control doesnt come back for further processing. I tried using select, but it didn't work... Any help would be greatly acknowledged.:) (2 Replies)
Discussion started by: Harish.joshi
2 Replies

9. Programming

Problem Connecting to Socket

Can anyone help? I'm trying to write a program which will write to a socket. I can get the server to run, but always get an error when I try to connect. It gives me an error at the "connect" command. It's probably a simple error, but I can't seem to find it. #include <sys/socket.h>... (6 Replies)
Discussion started by: Stevhp
6 Replies

10. Programming

Socket Problem

Hi all, I have developed server/client application (using C) and tested it on the same machine .. but when I deploy them on different machines I get connection timeout. Well .. server machine and client machine exists on different network segments, so there is a linux firewall box to route... (3 Replies)
Discussion started by: Agent007
3 Replies
Login or Register to Ask a Question