Saturday, August 18, 2012

TCP Daytime client Program using C in linux

This is the client program to get the time and date. Daytime server is the server program which is provided by the linux, and it has a specific name in the system i.e. "daytime".


daytimecli.c
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netdb.h>

int main(int argc,char *argv[])
{
    int sockfd,len,ret;
    struct sockaddr_in saddr;
    char *hname,buff[256];
    struct hostent *hostinfo;
    struct servent *servinfo;

Thursday, August 2, 2012

Simple Client-Server network Program using TCP/IP stream sockets


This is a simple socket program, in which client sends a message to the server and server replies to the client. The server is waiting for the client process connections.

Server Program:
                                              server.c
#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<netinet/in.h> // for networkbyte order (htons(),htonl())
#include<arpa/inet.h>
#include<string.h>
#include<unistd.h>


int main()
{
    struct sockaddr_in saddr,caddr;
    int len,listenfd,sessfd,ret,retb;
    char buff[10]={0};