Sponsored Content
Top Forums Programming [C++] [Unix] TCP non-blocking. Detect server disconnection procedure over, from client. Post 302589331 by ikeban on Wednesday 11th of January 2012 10:31:27 AM
Old 01-11-2012
[C++] [Unix] TCP non-blocking. Detect server disconnection procedure over, from client.

Hello!

I searched forum for similar topic, with no luck, if you know one, delete this topic, and send me private message with link please.

Little background:
I have a lot of clients and one serwer. Client can make multiple connections on different ports and ips, but only one can be acctive (first have to be close before second is opened).
TCP connection is non-blocking.
Serwer and client detect different situactions (write, read, disconnect, connect) with operating system function : select().

I have to close connection in client, before i make new one. I do it like that:
Client:
Remove file descriptors from select pools, and close() file descriptor. Immediately make new connection on new port.

Serwer:
Select return 0 when read on closed port -> remove file descriptor. Then handle new connection.

That ok! but.... sometimes client make new connection really fast, and server get new connection event faster that disconnection event (disconnecting between socket is 2 phases procedure... so it take a little time).

So what I need to do:
I want to close socket in client, and wait until server confirm that disconnection was successful, before I make new connection. How to do this?
To start disconnecting procedure, I have to use close on file descriptor, but then i have to remove this file descriptor from select pool, or i will get "bad file descriptor" error from select. If I remove file descriptor from select pool, and then close... select no longer monitor this file descriptor, so i don't get any information from it.
First option was a timer -> client wait 500 ms before make new connection -> this help, but i don't want to use this 500 ms delay.. I want to make new connection as soon as server let me.
Second option that I checked, was reuse the same port.. but this is bad too, because when I try to use the same port i get error: port still used. Of course I can try to connect again, and it will finally work, but I really don't want to use this method (more reasons here, but hard to explain).

Do you have any idea how to wait in client to let server finish disconnection and detect this case? I can't modify serwer :/
Maybe there is something that i don't know about select? Should it return this error: "bad file descriptor"? There are really weak manuals on internet (not a lot of information).

Sorry for poor English skills.
Ikeban

Edit: I have other question, related to topic: How to start disconnecting procedure, without closing socket?

Last edited by ikeban; 01-11-2012 at 12:15 PM..
 

10 More Discussions You Might Find Interesting

1. Cybersecurity

RedHat9:How to find what is blocking the port 1526/tcp

I'm trying to configure IDS9.40 on Ret Hat 9. The server has opened the port 1526/tcp nmap (nmap -sT -O linux) reports correctly that the port is open. However, portqry (portqry.exe -n 192.168.0.101 -e 1526 -p TCP) reports that the port is closed for connection: TCP port 1526 (turbo... (0 Replies)
Discussion started by: Juhasz Lajos
0 Replies

2. UNIX for Dummies Questions & Answers

updating "share" without disconnection current client

I have a directory that is currently being shared by several clients. I would like to add another client and be able to mount it without kicking the other clients off. I edited /etc/dfs/dfstab and added the client's hostname towards the end the line. i.e. share -F nfs -o... (3 Replies)
Discussion started by: benq70
3 Replies

3. Programming

tcp server listening, client connecting problems

hello everyone. I tried searching for something related to this, but I figured it was time to ask my own question. I am experiencing these problems using Ubuntu 7.04 I am starting up a TCP listener/server and once connected, will act as a communication/control link with a program on another... (3 Replies)
Discussion started by: pjwhite
3 Replies

4. Programming

can-not detect TCP disconnects well

Hello everyone. Thanks for reading. I am using Ubuntu 7.04 to experience this problem: I have written my own programs that communicate to eachother and I am having a hard time detecting a TCP socket disconnect when the remote side's computer has a power-failure (for example). On the computer... (6 Replies)
Discussion started by: pjwhite
6 Replies

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

6. Programming

How detect TCP/IP socket shutdown when ethernet cable is disconnected

Hi, I want to code TCP/IP client/server in linux application capable to fastly detect ethernet cable disconnection in any condition. So I have activate SO_KEEPALIVE options and set TCP_KEEPCNT, TCP_KEEPIDLE and TCP_KEEPINTVL to 1. When I disconnect ethernet cable I have the following... (5 Replies)
Discussion started by: jeje_clb
5 Replies

7. Windows & DOS: Issues & Discussions

Office server => laptop =>client server ...a lengthy and laborious ftp procedure

Hi All, I need your expertise in finding a way to solve my problem.Please excuse if this is not the right forum to ask this question and guide me to the correct forum,if possible. I am a DBA and on a daily basis i have to ftp huge dump files from my company server to my laptop and then... (3 Replies)
Discussion started by: kunwar
3 Replies

8. Red Hat

I want to know the disconnection time of my broadband tcp/ip connection.

Hello, I want to know the disconnection time of my broadband tcp/ip connection as it got disconnected while downloading data. I use Vuze bit torrent client and JDownloader . I use broadband internet connection and my os is slack 11. The problem I have been facing for last 2/3 days that my... (1 Reply)
Discussion started by: vectrum
1 Replies

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

10. UNIX for Advanced & Expert Users

How to detect files transmission at UNIX server ?

Dear Expert Users, I know that Unix utility ( fuser ) is used to detect "transmission" of files from Source system to "current Linux Server". I have scheduled this Unix script to work every 30th minutes of the hour and whenever files transmission starts at that very moment. And, the file... (4 Replies)
Discussion started by: schandrakar1
4 Replies
tapset::tcp(3stap)														tapset::tcp(3stap)

NAME
tapset::tcp - systemtap tcp tapset DESCRIPTION
This family of probe points is used to probe events that occur in the TCP layer, tcp.sendmsg Sending a tcp message See probe::tcp.sendmsg(3stap) for details. tcp.sendmsg.return Sending TCP message is done See probe::tcp.sendmsg.return(3stap) for details. tcp.recvmsg Receiving TCP message See probe::tcp.recvmsg(3stap) for details. tcp.recvmsg.return Receiving TCP message complete See probe::tcp.recvmsg.return(3stap) for details. tcp.disconnect TCP socket disconnection See probe::tcp.disconnect(3stap) for details. tcp.disconnect.return TCP socket disconnection complete See probe::tcp.disconnect.return(3stap) for details. tcp.setsockopt Call to setsockopt() See probe::tcp.setsockopt(3stap) for details. tcp.setsockopt.return Return from setsockopt() See probe::tcp.setsockopt.return(3stap) for details. tcp.receive Called when a TCP packet is received See probe::tcp.receive(3stap) for details. SEE ALSO
probe::tcp.sendmsg(3stap), probe::tcp.sendmsg.return(3stap), probe::tcp.recvmsg(3stap), probe::tcp.recvmsg.return(3stap), probe::tcp.disconnect(3stap), probe::tcp.disconnect.return(3stap), probe::tcp.setsockopt(3stap), probe::tcp.setsockopt.return(3stap), probe::tcp.receive(3stap), stap(1), stapprobes(3stap) IBM
--- tapset::tcp(3stap)
All times are GMT -4. The time now is 02:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy