Programming :: Closing Multiple Client Sockets In Server ?
Nov 30, 2010
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 have question about the UNIX sockets. my goal is to connect multiple sockets from a single client to a single server and keep them open...I'm not sure if that is possible to create or not. Do you have any suggestion or an example of code?
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 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.
I am trying to write a chat program with sockets as part of my project. I made a socket server, using fork ,I tried to connect it with different clients.Each client will send messages to others through server.So server has a shared memory storing every clients username and client id. But the problem facing is first client is able to sent messages to every other client formed after that.But second client onwards it is not able to sent message to previously connected ones. Server is not able to write on those client id's.
I am struggling a little on how to best approach this problem. I have wrote a server program that runs via xinetd, that obviously spits out data at the client end. Fairly straightforward stuff?There is a point in my server code where I need to display an image/gui i.e something that runs on X11 that prompts a user to perform a task on the display connected at the the server side.So far I have written a test program that displays some text at the client end and then launches the browser at the server end. I have also set the following export. Code: export DISPLAY=:0 and then goes on to launch my web browser. Works great when ran locally on the server and when I remotely telnet in to the server and run the code.
However when I try to run the same piece of code as a xinetd service the export seems to have zero affect and the client terminal window displays errors associated with there not being a X11 server running.The code launches fine when I create a socket to serverip:6556 it just the ability to display gui programs to another display that does not seem to be working.
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.
Instead, it uses "setsockopt" to set some options.
My guess is that it is trying to send packets over the eth0 interface instead over the wl0 (wireless) interface (which is the one I want to use to send pings).
Now, my question is: Is there any other way to send pings in C by binding to an interface?
I need to create a C/C++ program in Linux that succeeds in detecting how many tcp-sockets and what tcp-sockets are created by the other processes in the system in a particular time interval (e.g., the interval time this application is running in). Then, I'd need to get some information like local/remote port number and local/remote ip address of each of these sockets.
Can someone help me with this problem,trying to send a packet,using tcp/ip,the packet should look like this:
Code: field 1: SOCKS protocol version, 1 byte (0x05 for this version) field 2: status, 1 byte: 0x00 = request granted 0x01 = general failure 0x02 = connection not allowed by ruleset 0x03 = network unreachable 0x04 = host unreachable 0x05 = connection refused by destination host 0x06 = TTL expired 0x07 = command not supported / protocol error 0x08 = address type not supported field 3: reserved, must be 0x00 field 4: address type, 1 byte: 0x01 = IPv4 address 0x03 = Domain name 0x04 = IPv6 address field 5: destination address of 4 bytes for IPv4 address 1 byte of name length followed by the name for Domain name 16 bytes for IPv6 address field 6: network byte order port number, 2 bytes and this is my code:
Code: int domainLen = strlen(domain); char reply[domainLen + 7]; reply[0] = 5; // version reply[1] = 0; // succed reply[2] = 0; // reserved reply[3] = 3; // its a domain reply[4] = domainLen;; // lenght of domain for(int j = 0; j < domainLen; ++j) { reply[j + 5] = domain[j]; } reply[5 + domainLen] = 80; // port reply[20] = '�'; Send(reply, sizeof(reply)); domain is "www.google.com". Am I doing it right ? I dont know much about bits.
I am doing a project where 2 clients connect to server and communicate (chat) and transfer data one after other using sockets. I have working code for this in C language. Now our main aim is to create a communication link where two clients transfer multiple streams data parallely. To be more precise i want to transfer images files and audio files parallel at same time, so is it possible to send data parallel using one socket connection?
I am using the API libpcap in order to filter the traffic of the port 53 from my PC ro other PCs, in other words the DNS traffic.I want to get more information about the DNS traffic that is being sent to the DNS server, in other words the queries. So far I have no idea how to read the information data or payload of the UDP package in order to read the content of the traffic for example if there is any PTR, A, MX, etc Resource Record.According to the RFC 1053 there is a header that is possible to use in order to easily get this info.
NextPendingConnection () returns a new socket with respect to a new client. This new QSocket is passed to the connect () function which connects it to a SLOT 'xyz' with SIGNAL 'readyRead()'. Now in the SLOT 'xyz' how I am supposed to automate the monitoring of ALL connected sockets to see whether some data is available on them? One pathetic way would be to run all the sockets through a for loop and check each one of them for the data. Secondly, I read up on QSocketNotifier() here: [URL]. But I am not sure if that is the correct thing.
I am coding a http server which has to send the file(s) such as images, .avi files, .mpeg, that the client is going to request. I have been trying of sending files through sockets.
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 passing a file descriptor from one process to another.
I have two processes A and B. Both are running in different network and filesystem namespaces, so it is impossible to use unix domain sockets or net sockets to pass a file descriptor from process A to process B.
The usage of STREAMS is also impossible, as you can see in fixunix.com/unix/84093-streams-pipes-ioctl-i_sendfd.html
[quotation begin] Linux doesn't have STREAMS, which are the System V way of doing this task. ... [quotation end]
Are there additional possibilities for file descriptor passing like using named pipes or something like that or does anybody know a good workaround for this problem ?
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).
Iam using socket programming in one of my problem. The scenario is like this.
=>one module is working as a socket server(process p1) is able to handle client sockets on that port. =>one module is working as socket client (process p2) is connected to server socket and Tx/Rx data on this socket. This module has some more threads, based on received data from server socket it will connect to http on other thread and get information... =>one more module is working as socket client (process p3) is also connected to server socket and doing some other transactions.
Here my problem is when in presence of p2, p3 http connection taking more time than the expected. If we wont start p3(means only one server-client socket) then http connection is fast enough.
constructing a protocol where in it involves sending and receiving different files, so sending data over consists of file name, size of the file and content of the file, so while receiving can i use functions like strchr() to differentiate these fields for sockets? so to allocate memory for file to save i need to have its size.
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?
I configured openLdap in RHEL5 on virtual achines,everything is working fine, I created a user called ldapuser,in LDAP server and i created a home directory for ldapuser in my LDAP client, now i can able to login to the both Server and client with ldapuser account....
Now here what am expecting is i want to export my server's home directory to the client, i dont want to create home directories manually in the client machine, i googled about that, and it can be done through autofs.....
what need to be done on the client and server side.
I am working with DM355 target board. Here we record. The video coming from IP cameras. Now I have to write c program for copying. The recorded avi files with date and time to NAS server using scp. I wrote a script to copy single file to NAS server.
I'm trying to add local sockets in my multi-threaded application in order to exchange data between threads. The only problem I got is that most of the information available on the net is related to internet oriented socket programming whileI want to perform local connections. got a thread that does the sniffing via libpcap. And I would like that thread to send each captured packet to a second thread that will analyse the packetof the thread implementations is written in separate .h file.Or maybe there is a more effective method of exchanging data between threads
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.