Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ winsock tutorials

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat May 17, 2008 1:09 pm    Post subject: C++ winsock tutorials Reply with quote

Are there any good C++ winsock tutorials out there that any of you know of. I really want to learn this, but I've only found one, and it's ok...not very detailed so sometimes I just have to go along without the proper knowledge.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Sat May 17, 2008 7:12 pm    Post subject: Reply with quote

I have yet to see any nice full tutorials for it other then stuff for MFC. If you want to learn by reading other sources, download some old MUD source codes. You can find a ton of them at www.mudmagic.com
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Sat May 17, 2008 7:47 pm    Post subject: Reply with quote

Here's just a basic one. You should be able to get the idea from it.
Sends an HTTP GET request, recvs the page, then prints it out.

Code:
#include <cstdlib>
#include <iostream>
#include <winsock2.h>
#include <stdio.h>
#include <fstream>
#include <windows.h>

using namespace std;

int main()
{
   
    WSADATA WSAData;
            WSAStartup(MAKEWORD(2,0), &WSAData);
            SOCKET sock;
            SOCKADDR_IN sin;
            char buffer[1024];
            int c = 0;
            string source;
            string sendstr;
    struct hostent* host;

host = gethostbyname("cheatengine.org");
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_addr.s_addr = ((struct in_addr *)(host->h_addr))->s_addr;
sin.sin_family = AF_INET;
sin.sin_port = htons(80);
connect(sock, (SOCKADDR *)&sin, sizeof(sin));

 source = "";
   sendstr = "";
    sendstr = "GET /aboutce.php HTTP/1.0\n";
    sendstr += "Host: cheatengine.org\r\n";
    sendstr += "\r\n"; 
                  
         send(sock, sendstr.c_str(), sendstr.size() + 1, 0);
         for(c=1;c>0;c = recv(sock, buffer, sizeof(buffer), 0))
           source += buffer;
           
           
           closesocket(sock);
           cout << source;
           
           
    system("PAUSE");
    return EXIT_SUCCESS;
}

_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat May 17, 2008 11:20 pm    Post subject: Reply with quote

How come everyone uses v2.0 instead of v2.2?
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
STN
I post too much
Reputation: 43

Joined: 09 Nov 2005
Posts: 2673

PostPosted: Sun May 18, 2008 6:30 am    Post subject: Reply with quote

doesn't matter really. The OS will use version 2.0 even if theres a higher version available because this is what is requested.

Read the winsock help api for more info. Here's a snippet of api details.
Quote:

In order to support future Windows Sockets implementations and applications which may have functionality differences from current version of Windows Sockets, a negotiation takes place in WSAStartup. The caller of WSAStartup and the Windows Sockets DLL indicate to each other the highest version that they can support, and each confirms that the other's highest version is acceptable. Upon entry to WSAStartup, the Windows Sockets DLL examines the version requested by the application. If this version is equal to or higher than the lowest version supported by the DLL, the call succeeds and the DLL returns in wHighVersion the highest version it supports and in wVersion the minimum of its high version and wVersionRequested. The Windows Sockets DLL then assumes that the application will use wVersion. If the wVersion field of the WSADATA structure is unacceptable to the caller, it should call WSACleanup and either search for another Windows Sockets DLL or fail to initialize.

This negotiation allows both a Windows Sockets DLL and a Windows Sockets application to support a range of Windows Sockets versions. An application can successfully utilize a Windows Sockets DLL if there is any overlap in the version ranges. The following chart gives examples of how WSAStartup works in conjunction with different application and Windows Sockets DLL versions:

App versions DLL Versions wVersion
Requested wVersion wHigh
Version End Result
1.1 1.1 1.1 1.1 1.1 use 1.1
1.0 1.1 1.0 1.1 1.0 1.0 use 1.0
1.0 1.0 1.1 1.0 1.0 1.1 use 1.0
1.1 1.0 1.1 1.1 1.1 1.1 use 1.1
1.1 1.0 1.1 1.0 1.0 Application fails
1.0 1.1 1.0 --- --- WSAVERNOT
SUPPORTED
1.0 1.1 1.0 1.1 1.1 1.1 1.1 use 1.1
1.1 2.0 1.1 2.0 1.1 1.1 use 1.1
2.0 2.0 2.0 2.0 2.0 use 2.0

_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites