Friday, 12 August 2011

TCP Chat Program

                                             Tcp Chat program is similar to simple tcp client server communication, but it requires loop at both side and include the below function with the tcp server and client program

 //    Include at client side for client chat

Char opt;

printf("Enter ur wish to continue y / n);

scanf("%c",&opt);
while(opt!='y')
{

printf("Type ur client message\n");
    scanf("%s",buff);

// send  msg to server
    send(sockfd,buff,1024,0);


    recv(connfd,buff1,1024,0);

    printf("Serever msg received by client  %s",buff1);      

}


//  Include at server side for server chat


Char opt;

do{

    recv(connfd,buff1,1024,0);

    printf("Serever msg received by client  %s",buff1);   

    printf("Enter ur wish to continue y / n);

scanf("%c",&opt);

   printf("Type ur client message\n");
 scanf("%s",buff);

// send  msg to server
    send(sockfd,buff,1024,0);


} while(opt!='y')







1 comment:

  1. CHECK THIS C CODE FOR THE CHESS BOARD
    #include
    #include
    struct numbers{
    int a,b,e,f,x,y,det;

    };
    main()
    {
    typedef struct numbers numbers;
    numbers chess;
    int c=4,d=3;
    printf("\t\t\t\tCHESS BOARD\n\n\n");
    printf("\t\t");
    for (chess.x=0; chess.x<=7; chess.x+=0)
    {
    for (chess.y=0; chess.y<=c; chess.y+=0)
    {
    printf("/");
    chess.y=chess.y+1;
    }
    chess.x=chess.x+1;
    }
    printf("////\n");
    for (chess.f=0; chess.f<=3; chess.f+=0)
    {
    for (chess.a=0; chess.a<=d; chess.a+=0)
    {
    printf("\t\t//");
    for (chess.e=0; chess.e<=3; chess.e+=0)
    {

    for (chess.b=0; chess.b<=c; chess.b+=0)
    {
    printf("#");
    chess.b=chess.b+1;
    }
    for (chess.b=0; chess.b<=c; chess.b+=0)
    {
    printf(" ");
    chess.b=chess.b+1;
    }
    if (chess.e==3)
    {
    printf("//");
    }
    chess.e=chess.e+1;
    }
    printf("\n");
    chess.a=chess.a+1;
    }
    for (chess.a=0; chess.a<=d; chess.a+=0)
    {
    printf("\t\t//");
    for (chess.e=0; chess.e<=3; chess.e+=0)
    {
    for (chess.b=0; chess.b<=c; chess.b+=0)
    {
    printf(" ");
    chess.b=chess.b+1;
    }
    for (chess.b=0; chess.b<=c; chess.b+=0)
    {
    printf("#");
    chess.b=chess.b+1;
    }
    if (chess.e==3)
    {
    printf("//");
    }
    chess.e=chess.e+1;
    }
    printf("\n");
    chess.a=chess.a+1;
    }
    chess.f=chess.f+1;
    }
    printf("\t\t");
    for (chess.x=0; chess.x<=7; chess.x+=0)
    {
    for (chess.y=0; chess.y<=c; chess.y+=0)
    {
    printf("/");
    chess.y=chess.y+1;
    }
    chess.x=chess.x+1;
    }
    printf("////\n");



    getch();
    return 0;
    }

    ReplyDelete