Sockets in C++

This is a discussion on Sockets in C++ within the Networking/Device Communication forums, part of the General Programming Boards category; Please I just want to know how to use and how to control the sockets??? I have no idea .... ...

  1. #1
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112

    Question Sockets in C++


    Please I just want to know how to use and how to control the sockets??? I have no idea ....
    Ill be so Pleased & grateful for any explanation!!!
    and also if anyone knows a page in the web!!!
    so thx in adv.
    love,
    abyssphobia
    Last edited by abyssphobia; 08-18-2004 at 03:51 PM.
    Have I crossed the line?

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    You'll get more answers on this in the Networking/Device Communication forum (just so you know for any future posts). A moderator will most likely move this post in a little bit.

    http://www.google.com/search?num=50&...al&btnG=Search
    there's a list of tons of sites you can check out

  3. #3
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    well what I usually do is build a wraper class around the C sockets....

    something like
    Code:
     
     
     
    		class tcp
    		{
     
    		 private:
     
     
     
    			 int sockfd;
    			 struct sockaddr_in address;
    			 char buffer[1000];
     
    		 public:
    			tcp(char *,int);
    			int send(char*,int)
    			int receive();
    			~tcp();
     
     
    		};
     
     
     
     
     
    		tcp::tcp(char *ip,int port)
    		{
     
    		sockfd=socket(AF_INET,SOCK_STREAM,0);
    		if(sockfd==-1)
    {
    //some error handling
    		 return;
    } 
     
    		address.sin_family=AF_INET;
    		address.sin_port=htons(port);
    		address.sin_addr.s_addr=inet_addr(ip);
    		memset(&(address.sin_zero),'\0',8);
    		if((connect(sockfd,(struct sockaddr *)&address,sizeof(struct sockaddr)))==-1)
    {
    //some error handling
    		 return;
    }
     
    		return;
    		}
     
     
    		tcp::~tcp()
    		{
    		 close(sockfd); 
    		} 
     
    	 int send(char *message,int length)
    	{
     
    return send(sockfd,message,length);
     
    }			
     
    int receive()
    {
    return receive(sockfd,buffer,1000);
    }

    Actually you can build an abstract class which can be used by your other classes and make it more elegant with the functionality needed....
    Last edited by vasanth; 08-18-2004 at 03:56 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Best way to poll sockets?
    By 39ster in forum Networking/Device Communication
    Replies: 3
    Last Post: 07-22-2008, 01:43 PM
  2. Cross platform sockets
    By zacs7 in forum Networking/Device Communication
    Replies: 5
    Last Post: 06-27-2007, 05:16 AM
  3. multiple UDP sockets with select()
    By nkhambal in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-17-2006, 06:36 PM
  4. Raw Sockets and SP2...
    By Devil Panther in forum Networking/Device Communication
    Replies: 11
    Last Post: 08-12-2005, 04:52 AM
  5. Starting window sockets
    By _Cl0wn_ in forum Windows Programming
    Replies: 2
    Last Post: 01-20-2003, 10:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21