Programming :: How Could Server Detect Closed Client Socket Using TCP And C++
Aug 6, 2010
Reading some examples on net and copying some codes I was able to build a (frankstein) server that accept connection from one client and receive and send messages to it. The big problem that shows up is that I don't know when client disconnects from my server.
I've been looking for a solution, but no success. I'd read about SO_KEEPALIVE option (which could solve my problem), but I don't know how to use it (how to check the value of it).
I can't use ping because the server (machine) could be running, but not the client (software).
Anyone knows a good tutorial or how to (for beginners like me xD) of TcpIp sockets using c/c++ and how to detect when a client disconnect?
iam just trying to connect to server which accepts one client and server will read(blocking operation) infinitely, but After closing the client socket the server "read operation" is returning zero and "errno variable(in errno.h)" value is also zero. how can i detect whether a client socket is closed/active..?
I am writing a TCP server in C, and the server listens to incoming client connections and accepts them. It then creates a thread to handle the client. The clients are expected to only receive data from my server and not send any data. So if I use a select() call with a recv(), I believe that the recv() will just block forever since there will not be any data coming from the client. If I use a non-blocking recv(), then this will just return a 0 which tells me nothing because the client is not expected to send any data. I am not sure if I have misunderstood some socket concepts, but I need a solution to detect when the client has disconnected so that I can close the socket and stop sending data to the client. As I understand it, simple ACKs etc are not captured by the recv(), and only data sent by the client will cause recv() to return a non-zero value, so I am not sure how to know when the client has disconnected.
i have a server program which accept multiple client connection and am using polling. like every 2 secs it will look to client whether any data is received after it binded. i have used setitimer but there is runtime error i got.. the server accept all client connection but doesn't execute any msg which client sent.
I want to built a Chat Program (based on Socket connection) between client and server. I use the GTK+ &GLADE graphic tool. Can you send me the code for this program or any material to learn. Also, I want to know how to show the input to text view (in GTK+&Glade).
we have a multi threaded program on Linux where one thread is waiting on poll() system call with event set to POLLIN, & another thread has closed the same socket fd (which is passed to poll) , but the poll() did not return, is this the expected behavior? From man page of poll we found that the poll should return POLLNVAL if the socket fd is closed, is my understanding correct or is there any bug in the poll()?In Solaris we observed that the poll system call is returning with POLLNVAL if the socket is closed.
I have a server listening on incoming client connections. Once the client establishes SSL connection with the server, the server waits on read() from the client. Only Client can disconnect the connection. I want to have a timer in the server program to wait for x secs after read() and then disconnect the Client connection.
Is it possible to swap a client ip and port ? This is what I am trying to do. Let say you have Comp1 and Comp2 And you have Server between them. My goal is to get Comp1 and Comp2 know each others IP So Comp1 connects to server And server stores comp1's IP In a text file or other place And Comp2 connect to server And server also stores his info And then both comp1 and comp2 dowload the tex file And use the info on it.
Elementary... Here's the tricky part: next i have to handle user level ack the server is sending to "client"... To do that i have to open server socket on the same port number the system assigned to my client socket before. How can i get it ( in user level code)?
I want to get the connected client MAC Address after accept() call. I can get the IP address of the client but i don't know how to get the client MAC Address in my this programme. Here I am Posting my Code.
I have a java application that I wrote recently. It runs off port 9955. The application runs great on my mac server. When I installed it on my linux box i cant get to it from outside the box. A port scan shows the port as closed. I flushed my iptables, did not help. I can telnet into the app locally, from the server and it works great. I cannot telnet from outside the server. I have a reference to the application in /etc/services as a tcp port (which it is).
While creating a new VM for Win2K, I guet the following error when I try to "Finish":
Code:
Unable to complete install '<class 'libvirt.libvirtError'> socket closed unexpectedly Traceback (most recent call last): File "/usr/share/virt-manager/virtManager/create.py", line 717, in do_install dom = guest.start_install(False, meter = meter)
[code]....
This looks like a SELinux issue, since I do get a warning: SELinux is preventing qemu (qemu_t) "search" to / (fusefs_t). I'm attaching the complete SELinux Alert.
I am looking to be able to connect to an IRC server in a C program. I have followed some instructions from an old book I have however it doesn't seem to be working. I've tried connecting to localhost on my ssh port and it still doesn't want to work. This is what I have so far as a piece of skeleton test code:
the above code works fine.if we copmile and run ./a.exe 192.xx.xx.xxx 1111 and press enter it works fine..everytime it asks "Please enter the message: " and if give that will be displayed in server. but my problem is i dont want to print everytime "Please enter the message: " i just want to feed some words one by one to the socket.
im getting that error in my code for some reason. I compiled my code, and when i try to run this server it throws me an error on my call to setsocketopt(). The only way it can reach that part of my loop is if it succeeds when it calls sock() so I dont understand why the error says its an operation on a non-socket. Im just trying to set up a server to pass messages from a client to it a viceversa. Here is the code:
Code: int main() { int socket_fd, new_socket_fd, k; struct addrinfo hints, *server_info, *p; struct sockaddr_storage peer_address; code....
I am currently programming a suite of daemons in c++ on CentOS 64. More or less all those daemons are SOAP servers, with the SOAP part handled by gSOAP.
One of the daemons is a monitor sitting on a certain server and more or less just checking if the other daemons are up and running - but also offering a SOAP interface to get the 'current situation' on the machine.
Whenever the detected situation does not correspond to the defined (i.E. a process which should be is not running) it is started up.
This part, I implemented via a system() call that starts the other process.
I was a little confused when lately often this monitoring process would not start because it could not bind its server port - the one the SOAP server is listening on.
And confusion got bigger when netstat told me that the port is assigned to one of the processes that were before started by the monitor..?
Even better: if I then kill the process of which netstat tells me it holds the port, the next netstat shows the next monitor-started process as the one listening on the port..
Only if I kill all the processes that were started by the monitor, the port is released and I am able to launch the monitor again.
Now I wonder: why does this port get 'reassigned' to the children - and most of all: how can I prevent this from happening?
I'm trying implement a small server for a university work, my server is creating, binding and listening but it don't accept any connection, these are the files I'm using in server:
Code:
// Definition of the Socket class #ifndef SOCKET_H #define SOCKET_H #include <sys/types.h> code....
I've made a client just for test it, but no ones run well, the server is always returning -1 when accept is called!!
What should I do to send and receive messages in this server??
I would like to play .mp3 and .mpeg files with Red Hat Enterprise Linux 6 Client. Flash and Java must also be working. For Java, I have download the jre-6u22 and the jdk-6u22 and installed manually. How can I get automatically updates for them? For Flash, I have installed the i386 package and the .repo so the updates must working. So, I have
Enabled are only Adobe, RHEL Client v6 for 64-bit x86_64 and the RHEL 6Client - RPMforge -dag repositories. The others make problems with dependencys. RPM Fusion has no EL 6 repos, so I deactivate them. I have chosed to install the gstreamer plug-ins bad but haven't find them. Manually download from rpmfind or pbone results with wrong depencies...it's horrible.
I'm building a simple(?) socket server using threads to serve up a few requests. The spec is such that I have to listen to three ports at once, so I decided to use pthread to create three separate threads that would wait for connections, then spawn new threads to handle them.
The problem is that when I do this, for some reason the program never enters the wait loop and instead terminates (All three threads did get created since the messages get printed properly.) It gets to the line which prints "???", but not the line after the accept() call.I don't see an open port when I check for one either so I'm 99% sure they're terminating.Basically I have a main() method which has three calls to pthread_create, which should result in three threads being run that all wait for connections (listenOnPort). After each thread creation I print some info to make sure it's actually being created.
By the way, when I just run listenOnPortwithout threading, the server appears to enter the loop correctly and seems to be waiting for requests. It's only when I run the functions as threads that the problem seems to happen.The source is attached below. Any help will be appreciated. Much of the code is borrowed from a website (I can't post it because I am new here.) You need not worry about the handler_ methods because those are just methods that are run by the threads themselves.
Also--the original source was in C and I changed it to C++. Should I just use C? server.h Code: /* * server.h
I've been attempting to figure this out for about 4 days straight, so far it has not been fruitful. I've installed Ubuntu 10.04 server onto my former gaming system, Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz, 2 cores with 2 GB ram. Overkill I'm sure, especially for a simple personal voip, htpc, storage server.
The problem is only noticeable when I have the vent server running, on the 10.04 server, and I attempt to connect to it through the LAN via the client on my windows computerEverything works fine and connects, LAN and from the outside, as long as the server is set to DHCP. However when attempting to switch to a static IP address, the vent client will not detect the vent server at all.Aside from an annoyance at having to stick with DHCP, I am still curious as to why the static settings will not function. Something so simple has turned into something quite difficult.
I can still connect to the Webmin interface and Putty into server with either DHCP or static IP enabled.I've performed the following troubleshooting steps so far:1) Followed the directions at https://help.ubuntu.com/8.04/serverg...iguration.html2) Edited the /etc/network/interfaces file through the CLI with nano and through notepad on the windows computer3) Through Webmin I've assigned the static IP, although for some reason it does not include a gateway field.4) I've rebooted the server5) I've issued the CLI
Code: sudo /etc/init.d/networking restart Here is the file /etc/network/interfaces:
In all the examples I have found the server accepts the client's conection, proccess the data received and close the socket. In an very schematic way it would be something like:
Code:
client_thread{ select to see if there is data to read from socket fd if there is something to read{
[code]....
Should I use mutexs or semaphores to block the socket fd before read and write or it is not necesary?
I looking for an algoritm to encrypt some data sent from a c program(client) to a php server(can be in perl or cgi-bin) over the internet. How should i send it in c? Some http call? Or it can be in via a perl script. Then i need some basic algoritm to encrypt it. Any ideas. How do i save the key in the c program? Just something basic so its not clear text. This is not for a bank or visacards etc
I have a problem creating my second socket in client file. the program was running well but when I try to add another socket to connect to the same server, I got a problem connecting to the first socket! it doesn't make sense. the original code was:
I have written a server application which has select for both incoming new client connection requests and incoming data from client. I am able to process incoming connection requests and client data.
For example, server has 8 clients connected to it. If client 3 disconnects from server, how will server come to know this client has disconnected and to close its client socket fd gracefully? Does server's select get data on that client socket fd as 'close' data or any error code in recv() function that notifies server to close this client socket fd? Also if client disconnects abruptly without sending close request to server, how should server handle this? Does server get "EPIPE" error?
I am new in client server programming and i have written code for single server to single client communicating one port(3490). but i have no idea how my single server will be communicate with different client on different port.how this will be happen ?
Any idea to understand the logic or send any good link or any piece of code in c , i searched on net but all help was mostly for java progamming.