Click here to Skip to main content
12,621,424 members (29,710 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ C Windows Dev Win7
Dear Friends,
I have to learn the Socket programming in a minimum time period possible while I am a beginner in the C/C++ programing.
1- Which source is the best for learning this subject with windows 7 and Dev-C++?

2- It seems i have to add some libraries and I do not know where I have to download the right one and how to add them to my windows 7 and/or Dev-C++?

3- I need a very simple and complete workable example to let me read the http webpage and save the content in a text file using socket programing. (I could not run any example in the internet as I am not able to debug them!!!)

4- I am working on below client example but it has build error, may anyone help me?

Many Thanks in advanced for your quick reply.
Posted 26-Nov-12 23:48pm
Updated 1-Dec-12 20:01pm
v7
Comments
Richard MacCutchan 28-Nov-12 6:37am
   
We cannot guess what the error is; please provide the exact text of the error message.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

A Google search finds lots of suggestions[^].
  Permalink  
Comments
85223501 27-Nov-12 6:07am
   
I am afraid it did not help me at all.
Richard MacCutchan 27-Nov-12 6:12am
   
Try these links. While not specifically Dev C++, they should give you enough information to get started.
85223501 28-Nov-12 0:01am
   
Thanks.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

#pragma comment(lib,"Ws2_32.lib")

you should include it in your begining program.
sorry for my poor english .
  Permalink  
Comments
85223501 29-Nov-12 2:00am
   
Thanks a lot!
midle110 29-Nov-12 2:18am
   
You're welcome
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

I have a project on the site, Remote Control PCs[^], which has a socket class, based on events posted to the windows message pump. It seems like the easiest way to grasp sockets. The classes are TCPSocket.h/TCPSocket.cpp. With just a tiny bit of work you could extract and build a pair of DOS programs that work as a client/server
  Permalink  
Comments
85223501 30-Nov-12 9:01am
   
Thanks.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Reply1: It was not a good question, I found an online eBook in my mother tongue language and it helped a lot for me.

Reply2: In Dev we need to add libraries in two places; one in project options-->Parameters and the other is Tools--> Compiler Options--> Directories. I got that the libraries are in the installation path of my Dev software.

Reply3: DO NOT USE DEV while you are using windows dll, specially in Win7. It does not work at all!!!
Please use another compiler ....

Reply4: (corrected)--> This below code will be built in Dev but does not run properly so that it is not a practical example.
Collapse | Copy Code

#include < stdio.h>
#include < conio.h>
#include < stdlib.h>
#include < string.h>
#include < winsock2.h>

int main(int argc,char **argv){
     WSADATA wsaData;
     WORD wVersionRequested;
     SOCKET intSocket;
     struct sockaddr_in recSin;
     int intErr;
     char *pchrBuffer;
     
     if(argc<=2){
                 printf("::Error on the Call Program::\n");
                 printf("%s RemoteIPAddress RemotePort",argv[0]);
                 exit(1);
                 }
                 
     recSin.sin_addr.S_un.S_addr=inet_addr(argv[1]);
     recSin.sin_family=AF_INET;
     recSin.sin_port=htons(atoi(argv[2]));
     wVersionRequested=MAKEWORD(2,0);
                 
     if(WSAStartup(wVersionRequested,&wsaData)){
                                                printf("\n::Error on the INET Socket::\n");
                                                exit(1);
                                                }
     
     intSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
     
     if(intSocket==INVALID_SOCKET){
                                   printf("\n::Error on Create the Socket::\n");
                                   WSACleanup();
                                   exit(1);
                                   }
      intErr=connect(intSocket,(struct sockaddr *)&recSin,sizeof(recSin));
      
      if(intErr==INVALID_SOCKET){
                                 printf("\n::Error on Connect to the Socket::\n");
                                 WSACleanup();
                                 exit(1);
                                 }
                                 
      pchrBuffer="HI\0";
      intErr=send(intSocket,pchrBuffer,strlen(pchrBuffer),0);
      
      if(intErr==SOCKET_ERROR){
                               printf("\n::Error on the Data Send::\n");
                               printf("Error Code:%d",WSAGetLastError());
                               WSACleanup();
                               exit(1);
                               }
      memset(pchrBuffer,'\0',strlen(pchrBuffer));
      
      if(intErr==SOCKET_ERROR){
                               printf("\n::Error on the Data Receive::\n");
                               printf("Error Code:%d",WSAGetLastError());
                               exit(1);
                               }
                               
      printf("\nData Received:%s\n",pchrBuffer);
      closesocket(intSocket);
      WSACleanup();
      getch();
      }

[edit]code block added[/edit]
  Permalink  
v2
Comments
85223501 3-Dec-12 4:51am
   
What is the change?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.161128.1 | Last Updated 2 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100