Server Programming to keep on looking for client connection


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Server Programming to keep on looking for client connection
# 1  
Old 07-18-2009
Java Server Programming to keep on looking for client connection

Hi I wrote a server Program in C,

Here it is, this is a just socket creation alone,
Code:
bool myclass::CreateSocket()
{
    struct sockaddr_in sockaddr_in;
    sockaddr_in.sin_family = AF_INET;
    sockaddr_in.sin_port = 1100;
    sockaddr_in.sin_addr.s_addr = INADDR_ANY;
    mServerSockDesc = socket(AF_INET, SOCK_STREAM, 0);
    if(mServerSockDesc <= 0)
    {
        cout<<" Error: Server Socket Creation Failed - CreateSocket() ";
        return false;
    }
    mBindStatus = bind(mServerSockDesc,(struct sockaddr *) &sockaddr_in,sizeof(sockaddr_in));
    if(mBindStatus == -1)
    {
        cout<<" Error : Server Socket Bind Failed - CreateSocket() ";
        return false;
    }
    mListenStatus = listen(mServerSockDesc,10);
    if(mListenStatus == -1 )
    {
     cout<<" Error : Server Socket Listen Status Failed - CreateSocket() ";
        return false;
    }
    return true;
}

The Problem is, The server is not lisening to client after some time say 2 hour.

my server is running, and few clients are connected. after 2 hour, the client show it as connected, but it is not performing any operation. If i try to reconncet my client, the server is not accepting the client. When i saw the Log file, the server is not at all running.

The server has to Keep on running, it should not stop. At any time means after two days also if i try to connect it has accept my client connection.

Can any one help me in how to achive this?

Use CODE tags when displaying code, data or logs to enhance readability and to preserve formatting like indention etc., ty.

Last edited by zaxxon; 07-20-2009 at 09:29 AM.. Reason: code tags
# 2  
Old 07-18-2009
First of all, you are using C++ not C.

To correct you problem you need to add a loop after listen(). i.e.
Code:
 /*  Enter an infinite loop to respond to client requests  */
while ( 1 ) {

	/*  Wait for a connection, then accept() it  */
	if ( (connSocket = accept(mServerSockDesc, NULL, NULL) ) < 0 ) {
              /* add error handling here */
	}

        /* do processing here */
        
	/*  Close the connected socket  when finished  */
	if ( close(conn_s) < 0 ) {
               /* add error handling here */
	}
}

# 3  
Old 07-20-2009
Inside the While I'm listening for the New connection. Even though after some point of time, it is not ready to accept the client connection.
# 4  
Old 07-20-2009
Quote:
Originally Posted by vij_krr
Inside the While I'm listening for the New connection. Even though after some point of time, it is not ready to accept the client connection.
Could you rephrase that? I don't think the question translated.
# 5  
Old 07-21-2009
Quote:
Originally Posted by Corona688
Could you rephrase that? I don't think the question translated.
I think the OP meant, even after modifying the code with the suggestion posted, its still not accepting the connection as expected.

Could you please post the modified segment of your code?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

MOTIF programming and X11 client !

Hi there , i am interesting in MOTIF programming. One question : Is it right that in Motif GUI programming the actions are automaticly transformed and networked to other clients over the internet without network programming necessary ? Are the commands automatic transformed by the X11... (4 Replies)
Discussion started by: Zabo
4 Replies

2. IP Networking

Connection to DB from client server through jdbc:Oracle:Oci8 fail

We tried to use to connect to DB using jdbc:Oracle:Oci8:@<SERVICE-A>. Connection fail / refuse with one DB .But its working with other databases. But through toad, jdbc thin client were able to connect. But this has happen suddenly and were able to connect previously. How to navigate this... (0 Replies)
Discussion started by: udara
0 Replies

3. UNIX and Linux Applications

VMware View Client Connection Issues

I installed the VMware View Client for Linux in Ubuntu and whenever I try and connect I recieve: Untrusted View Connection: Failed to connect to the View Connection Server. The server provided an invalid certificate. The certificate authority is invalid or incorrect. Having access to... (2 Replies)
Discussion started by: metallica1973
2 Replies

4. Programming

Client Server programming

Hi Could someone give me some advise, basically i am learning UDP client server programming. I understand how to do send and receive between client server ( learn from this site Sending and Receiving Packets) but things such as MSN can actually send and receive at the same time! I believe it... (1 Reply)
Discussion started by: GQiang
1 Replies

5. IP Networking

Cisco VPN server and client - connection drop

I have a Cisco 1841 router configured as Easy VPN Server. Here is the configuration of the router: Cisco# Cisco#show running-config Building configuration... Current configura - Pastebin.com I have a Centos 5.7 server with installed Cisco VPN client for Linux. The client successfully... (0 Replies)
Discussion started by: rcbandit
0 Replies

6. Programming

socket programming using UDP connection

I want to send packets through single socket() but using two different port numbers in UDP. Anybody give some idea on this. Thanks in advance.:) (2 Replies)
Discussion started by: naresh046
2 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. Programming

Client/Server Socket Application - Preventing Client from quitting on server crash

Problem - Linux Client/Server Socket Application: Preventing Client from quitting on server crash Hi, I am writing a Linux socket Server and Client using TCP protocol on Ubuntu 9.04 x64. I am having problem trying to implement a scenario where the client should keep running even when the... (2 Replies)
Discussion started by: varun.nagpaal
2 Replies

9. Programming

Socket Programming - Port Scanner. I Get Connection Timed Out, Why?

When i put the target IP as 127.0.1.1, the program is working fine, can catch blocked & open ports. But when i try to scan remotely, i get connection timed out! Can you tell me why? :( Here is my code - Look at between where i put astriks - at the bottom: #include<iostream>... (3 Replies)
Discussion started by: f.ben.isaac
3 Replies

10. UNIX for Dummies Questions & Answers

socket programming : client server IPC

I'm new to socket programming. Have a basic doubt. I have a structure(global) at the server side. I have two different client connecting to the server. Will the changes made by one client on the structure be visible to the other client when it accesses the same client? I'm creating a STREAM... (3 Replies)
Discussion started by: abc.working
3 Replies
Login or Register to Ask a Question