Thread: Client/Server Programming!!!

  1. #1
    Registered User Silverdream's Avatar
    Join Date
    Feb 2002
    Posts
    53

    Client/Server Programming!!!

    Hi,
    I want to build a client/server chat program for the dos environment. I have no idea about socket programming. Is there any tutorial which can help me in this? Any website which explains this?

    Last edited by Silverdream; 03-29-2002 at 03:44 AM.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    42
    Check out these include files.

    #include <sys/socket.h>
    #include <netinet/in.h>

    You may want to really look at this structure.

    struct sockaddr_in servaddr;

    Code:
    /* create socket, quit if error */
    	if ( (sockfd = socket(AF_INET,SOCK_STREAM,0)) <  0) {
    		printf("socket error.\n");
    		exit(0);
    	}
    
    	/* servaddr values */
    	bzero(&servaddr, sizeof(servaddr));
    	servaddr.sin_family = AF_INET;
    	servaddr.sin_port = htons(atoi(argv[2])); 
    	servaddr.sin_addr.s_addr = inet_addr(argv[1]);
    	
    
    	/* connect to server, quit if error */
    	if(connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0) {
    		printf("did not connect!\n");
    		exit(0);
    	} else
    		printf("connected!\n");
    
        
    	/* Send message to server */
    	write(sockfd, serverMessage, strlen(serverMessage));
    http://www.KBeutler.com

  3. #3
    Registered User Silverdream's Avatar
    Join Date
    Feb 2002
    Posts
    53
    hi,
    Thanx for ur response. Could you please be more elaborate in your answer. I just wanted to start of with socket programming in C for dos. I cant understand ur code because its complicated for me to comprehend.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Well that's why learn about socket programming, BEFORE you ask questions about it. You might want to try Java for this program. It's very similar to C in structure, etc (like the {}'s), but it's all very simplified as far as the variety of functions go. It's C derived so you should pick it up quick, and was designed around this kind of problem. XML will help you a lot too.

  5. #5
    Registered User Silverdream's Avatar
    Join Date
    Feb 2002
    Posts
    53
    Thats why i had inlcuded in my question that i need a web site which has some tutorials/books on socket programming.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RE: client/server shared memory problem
    By hampycalc in forum C Programming
    Replies: 0
    Last Post: 03-10-2006, 02:26 PM
  2. NETWORKING: time client/server in C
    By ikaruga in forum C Programming
    Replies: 3
    Last Post: 08-22-2005, 05:58 AM
  3. Client/server won't connect
    By Lateralus in forum Networking/Device Communication
    Replies: 0
    Last Post: 06-15-2005, 07:48 AM
  4. Client/Server and Multithreading
    By osal in forum Windows Programming
    Replies: 2
    Last Post: 07-17-2004, 03:53 AM
  5. client/server program
    By purple in forum C Programming
    Replies: 3
    Last Post: 11-01-2002, 08:52 PM