Sponsored Content
Full Discussion: Tcp Ip Server
Top Forums Programming Tcp Ip Server Post 46989 by Perderabo on Friday 30th of January 2004 08:54:31 PM
Old 01-30-2004
I guess you're asking how to time out a read. There are lots of ways. My choice would be to use select().

select can monitor your fd and return when a read will succeed without blocking. Then you just read the data. But select also can be give a timeout. And it will return when time expires.

It's so easy, it's almost cheating.

poll() is another system call that is similiar to select().

Another approach is to use setitimer() or alarm() to request a SIGALRM and some point in the future. Then just do the read. Assuming that the SA_RESTART option is off for SIGALRM, the system call will not be restarted. It will fail with a EINTR error.

You could also put the read inside a signal handler for SIGIO. Then use fcntl() to arrange for the SIGIO when data is available for reading.

But these ideas are all generic stuff and you want something in the tcp library. In that case you can turn keepalives on. But since keepalives must comply with the rfc's, you have very little control over them.

I still say select() rocks. But it's your program. Smilie
 

10 More Discussions You Might Find Interesting

1. IP Networking

Tcp Ip Send Receive Server Program

Requirements: A server program should read a file and send the message to the client . if the file is not there, then switch to the receive part of the same program and receive any messages from the socket. If no messages to receive then switch to send part of the program to... (2 Replies)
Discussion started by: Rajeshsu
2 Replies

2. UNIX for Dummies Questions & Answers

Tcp-server

I have true64 Unix running and there a scales in the sytem which connect thru a com-server to the network. they have their own IP-address and are communicating over port 8000. when I telnet to the com-servers and the print function of the scale is executed I can see the data coming. I need to know... (1 Reply)
Discussion started by: albinhess
1 Replies

3. Programming

How to check TCP server status

Please tell me according to C/C++ socket programming; how client can check whether server is running or not during TCP communication. (1 Reply)
Discussion started by: mansoorulhaq
1 Replies

4. Programming

tcp server using pthreads is not working...ne help plz?

Hi, I am new to using threads in C++ though I have been wkring on C++ for past 1.5 years...I want to write a TCP server that serves multiple client connections...to start off..i have been working on a simple tcp echo server trying to understand how threads work.... this is my server code: ... (5 Replies)
Discussion started by: deepti_v25
5 Replies

5. IP Networking

TCP server dies after few hours of inactivity

We have a NAS application which can be accessed by both HTTP and HTTPS connections. The issue we are facing is that the tcp server instance that initiates the HTTP access dies after a few hours of inactivity(the NAS application was kept idle for around 10 hours). However, the tcpserver that... (1 Reply)
Discussion started by: swatidas11
1 Replies

6. Programming

Problem with tcp server

Hello @ all, I hope you can give me some advice :b: I will be following code for a tcp server and doStuff () function, the clients treated. From some point, I have several identical clients (zombies, I think), the same records in the database write. Has anyone an explanation? What can I... (1 Reply)
Discussion started by: yumos
1 Replies

7. Programming

Concurrent TCP client/server

I made a program and now I need to make it concurrent. Can someone pls help me do this ? The code is this: #include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> #include <netinet/in.h> #include <errno.h> #include <unistd.h> #include <stdio.h> #include <string.h>... (4 Replies)
Discussion started by: Johnny22
4 Replies

8. Solaris

TCP listner on Solaris server

Hi, I am having a solaris server. I want to start a dummy TCP listner on UNIX OS on a specific port can anyone please let me know the process. IP ADDRESS: 123.123.123.123 Port: 8010 (1 Reply)
Discussion started by: mayank2211
1 Replies

9. UNIX for Dummies Questions & Answers

Tcp connection to Linux server fails

I am trying to send json messages to a port on a linux server from a remote server running a .net program. I have one implementation running with successful incoming messages to port 1514. I tried to replicate the same thing but just to another port but cannot get it to work as I get the following... (3 Replies)
Discussion started by: unienewbie
3 Replies

10. Solaris

Too much TCP retransmitted and TCP duplicate on server Oracle Solaris 10

I have problem with oracle solaris 10 running on oracle sparc T4-2 server. Os information: 5.10 Generic_150400-03 sun4v sparc sun4v Output from tcpstat.d script TCP bytes: out outRetrans in inDup inUnorder 6833763 7300 98884 0... (2 Replies)
Discussion started by: insatiable1610
2 Replies
GETPEEREID(3)						   BSD Library Functions Manual 					     GETPEEREID(3)

NAME
getpeereid -- get the effective credentials of a UNIX-domain peer LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/types.h> #include <unistd.h> int getpeereid(int s, uid_t *euid, gid_t *egid); DESCRIPTION
The getpeereid() function returns the effective user and group IDs of the peer connected to a UNIX-domain socket. The argument s must be a UNIX-domain socket (unix(4)) of type SOCK_STREAM on which either connect(2) has been called, or one returned from accept(2) after bind(2) and listen(2) have been called. If non-NULL, the effective used ID is placed in euid, and the effective group ID in egid. The credentials returned to the accept(2) caller are those of its peer at the time it called connect(2); the credentials returned to the connect(2) caller are those of its peer at the time it called bind(2). This mechanism is reliable; there is no way for either side to influ- ence the credentials returned to its peer except by calling the appropriate system call (i.e., either connect(2) or bind(2)) under different effective credentials. One common use of this routine is for a UNIX-domain server to verify the credentials of its client. Likewise, the client can verify the cre- dentials of the server. IMPLEMENTATION NOTES
On NetBSD, getpeereid() is implemented in terms of the LOCAL_PEEREID unix(4) socket option. RETURN VALUES
The getpeereid() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indi- cate the error. ERRORS
The getpeereid() function fails if: [EBADF] The argument s is not a valid descriptor. [ENOTSOCK] The argument s is a file, not a socket. [ENOTCONN] The argument s does not refer to a socket on which connect(2) have been called nor one returned from listen(2). [EINVAL] The argument s does not refer to a socket of type SOCK_STREAM, or the kernel returned invalid data. SEE ALSO
connect(2), getpeername(2), getsockname(2), getsockopt(2), listen(2), unix(4) HISTORY
The getpeereid() function appeared in NetBSD 5.0. BSD
August 8, 2007 BSD
All times are GMT -4. The time now is 08:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy