Socket programming in C

Hi,

I wanted to write a socket program in C, where I always want my socket connected to the server. i.e i shouldn't get disconnected once i get the response back from the server. I want to work in the connected mode, instead of disconnect and connect.

Can somebody please kindly provide me a sample code how i will always be in connected mode to the server. ( Unix enviornment)

Thank you.
Best Regards
Sudharma

Program your client so that it doesn't disconnect itself, and tell the server not to disconnect your client when it's done. If that's possible depends on the protocol (of which you haven't told us anything), but HTTP and SMTP, for example, can work like this (although it's not exactly nice to hog up free sockets).

HTTP doesn't keep connection all the time. Isn't it?

@Topic
You can implement a socket program the way you like. Why should anyone want to have connection all the time, even when client and server have no communication going on?

you can use this working code :

void etherSetup(char *strIP,int nPort)
{
	unsigned long ip;
	
	if((*strIP <= '9') && (*strIP >= '0'))
		{
			if( (int)(ip = inet_addr(strIP)) == -1 )
				{
				printf("\r\nIP-address must be of the form a.b.c.d\n");
              	exit (2);
				}


		}
	else
		{
			server = gethostbyname(strIP);
    		if(!server) 
				{ 
				printf("\nError in host Name.\n");
				exit(2);
				}
   			ip = *(unsigned long*)(server->h_addr);
		}

/////printf("\r\nSERVER IP=%d\r\n ",ip);



	server = gethostbyaddr((char *)&ip,sizeof(ip),AF_INET);
	if (server == NULL)
		{
        	printf("\r\nERROR, no such host .\n");
        	exit(1);
    	}

	bzero((char *) &m_sockaddr_in, sizeof(m_sockaddr_in));

	m_sockaddr_in.sin_family = AF_INET;
	m_sockaddr_in.sin_port = htons(nPort);
	m_sockaddr_in.sin_addr = *(in_addr*)&ip;
	printf("remotehost : %s   , port : %d \n",strIP,nPort);
}

//-----------------------------------------------------------------
int Create()
{
  sockfd = socket(AF_INET, SOCK_STREAM,IPPROTO_TCP);
  if ( sockfd <0 ) return -1;
  return 0;
}
//-----------------------------------------------------------------
int Connect()
{
	int ret;

  	ret = connect(sockfd,(sockaddr*)&m_sockaddr_in,sizeof(m_sockaddr_in));
  	if ( ret <0 ) return -1; //ERROR in connection>
  	return 0;
}

this is for TCP/IP protocol