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 


[Rls] Communication through sockets

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Thu Sep 11, 2008 3:11 pm    Post subject: [Rls] Communication through sockets Reply with quote

Server

Code:

// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include <winsock2.h>
#include <windows.h>
#pragma comment(lib, "ws2_32.lib")

SOCKET SCKT;
HANDLE mutexHandle;
WSAData wsaData;
SOCKET ClientSocket;
struct sockaddr_in server;
struct sockaddr_in client;
int ServerSocket;
int clientsize = sizeof( client );
int nBytes;
char* buffer;

int InitServer( int PORT ) {

   int Error = WSAStartup( MAKEWORD( 2, 2 ), &wsaData );

   if ( Error == SOCKET_ERROR )
        return -1;

   ServerSocket = socket( AF_INET, SOCK_STREAM, 0 );

   if( ServerSocket == SOCKET_ERROR )
      return -2;

   server.sin_family = AF_INET;
   server.sin_port = htons( ( u_short)PORT );
   server.sin_addr.s_addr = INADDR_ANY;

   if ( bind( ServerSocket,( sockaddr* ) &server,sizeof( server ) ) == SOCKET_ERROR )
      return -3;


   if ( listen( ServerSocket, 10 ) == SOCKET_ERROR )
      return -4;

   ClientSocket = accept( ServerSocket, (struct sockaddr*)&client, &clientsize );

   if( ClientSocket != INVALID_SOCKET ) {

       for(;;) {

           WaitForSingleObject(mutexHandle, INFINITE);
         buffer = new char[512];
         int nBytes = recv( ClientSocket, buffer, 512, 0 );

         if( nBytes != SOCKET_ERROR ) {

            if( strcmp(buffer, "test") != 0 ) {
               MessageBox(NULL, (LPCWSTR)"Recieved message", (LPCWSTR)"", NULL);
            }

         }
      }


      return 1;

   }


}

void MainT(){

   InitServer(6297);

}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                )
{
   switch (ul_reason_for_call)
   {
   case DLL_PROCESS_ATTACH:
      CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&MainT, NULL, NULL, NULL);
   case DLL_THREAD_ATTACH:
   case DLL_THREAD_DETACH:
   case DLL_PROCESS_DETACH:
      break;
   }
   return TRUE;
}


Client

Code:

// client.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <winsock2.h>
#include <windows.h>
#include <iostream>

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


SOCKET SCKT;

bool _connect( void )
{
   WSAData WData;
   struct sockaddr_in VictimInfo;

   int GetError = WSAStartup( MAKEWORD( 2 , 2 ), &WData );

   if( GetError == SOCKET_ERROR)
   return false;

   VictimInfo.sin_family = AF_INET;
   VictimInfo.sin_addr.s_addr = inet_addr("127.0.0.1");
   VictimInfo.sin_port = htons( 6297 );

   SCKT = socket( AF_INET , SOCK_STREAM , 0 );

   if( SCKT == SOCKET_ERROR )
   return false;

   if( connect( SCKT,( sockaddr* ) &VictimInfo, sizeof( VictimInfo ) ) == SOCKET_ERROR )
   return false;

   return true;

}

void SendMSG( char* szMSG ) {
   send( SCKT, szMSG, 512, NULL );
}

int _tmain(int argc, _TCHAR* argv[])
{
   bool loop = false;
   char input[512];
   printf("Connecting to server...\n");

   if(!_connect()){
      printf("Could not connect...\n");
      system("pause");
      return -1;
   }
   
   do {
      printf("Enter a command\n");
      gets(input);

      if( strcmp(input, "exit") != 0 ) {
                        loop ^= 1;
      }

      if( strcmp(input, "command1") != 0 ) {
         SendMSG( "test" );
      }

   } while (loop);

   return 0;
}
Back to top
View user's profile Send private message
GMZorita
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Mar 2007
Posts: 1361

PostPosted: Thu Sep 11, 2008 3:29 pm    Post subject: Reply with quote

This is like shotting a fly with a cannon although its nice to control it from other comp.
Cgz on making it, and thanks for posting it.

_________________
Gone
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Thu Sep 11, 2008 3:32 pm    Post subject: Reply with quote

GMZorita wrote:
This is like shotting a fly with a cannon although its nice to control it from other comp.
Cgz on making it, and thanks for posting it.


Exactly, this method is very easy and reliable.
Back to top
View user's profile Send private message
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Thu Sep 11, 2008 3:37 pm    Post subject: Reply with quote

what is the @ server

WaitForSingleObject(mutexHandle, INFINITE);

doesnt it need

ReleaseMutex before next loop?

_________________
Hacks I made for kongregate.
Kongregate Universal Badge Hack: http://forum.cheatengine.org/viewtopic.php?p=4129411
Kongreate Auto Rating/Voter hack: http://forum.cheatengine.org/viewtopic.php?t=263576
Took a test lol
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Thu Sep 11, 2008 3:47 pm    Post subject: Reply with quote

pkedpker wrote:
what is the @ server

WaitForSingleObject(mutexHandle, INFINITE);

doesnt it need

ReleaseMutex before next loop?


Oh, ignore that. This is for something else. And no mutexHandle is not a mutex.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Thu Sep 11, 2008 5:06 pm    Post subject: Reply with quote

GMZorita wrote:
This is like shotting a fly with a cannon although its nice to control it from other comp.
Cgz on making it, and thanks for posting it.


Hmm, I think i've heard that saying before... Neutral
Back to top
View user's profile Send private message MSN Messenger
GMZorita
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Mar 2007
Posts: 1361

PostPosted: Thu Sep 11, 2008 5:52 pm    Post subject: Reply with quote

noz3001 wrote:
GMZorita wrote:
This is like shotting a fly with a cannon although its nice to control it from other comp.
Cgz on making it, and thanks for posting it.


Hmm, I think i've heard that saying before... :|

Uhh, its old.. but yeah u sayd it in some thread last time i saw it.What can I say? It express my thoughts...

_________________
Gone
Back to top
View user's profile Send private message
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Thu Sep 11, 2008 6:05 pm    Post subject: Reply with quote

Edit:
.credits. kthx


Last edited by slippppppppp on Thu Sep 11, 2008 6:28 pm; edited 1 time in total
Back to top
View user's profile Send private message AIM Address MSN Messenger
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Thu Sep 11, 2008 6:44 pm    Post subject: Reply with quote

ineffecient code flow... MessageBox can cause the missing of the next message ;](which could be another ConnectionRequest) xD
unless you create Socket Message Handler Thread on a Per Connect Basis
but it is a good first try.
Back to top
View user's profile Send private message MSN Messenger
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Thu Sep 11, 2008 8:21 pm    Post subject: Reply with quote

BanMe wrote:
ineffecient code flow... MessageBox can cause the missing of the next message ;](which could be another ConnectionRequest) xD
unless you create Socket Message Handler Thread on a Per Connect Basis
but it is a good first try.


Lol? The messagebox was just an example. No, there would not be another connection request. Please read the whole source.
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Fri Sep 12, 2008 12:23 am    Post subject: Reply with quote

noz3001 wrote:
GMZorita wrote:
This is like shotting a fly with a cannon although its nice to control it from other comp.
Cgz on making it, and thanks for posting it.


Hmm, I think i've heard that saying before... Neutral


'Cept you guys are both wrong, socket IPC is a common well-regarded methodology. Although usually it would be done with pseudo-sockets (named pipes are the same as this), but Microsoft has weird and vague APIs for that, whereas Winsock is well defined/supported.

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Fri Sep 12, 2008 3:34 am    Post subject: Reply with quote

nog_lorp wrote:
noz3001 wrote:
GMZorita wrote:
This is like shotting a fly with a cannon although its nice to control it from other comp.
Cgz on making it, and thanks for posting it.


Hmm, I think i've heard that saying before... Neutral


'Cept you guys are both wrong, socket IPC is a common well-regarded methodology. Although usually it would be done with pseudo-sockets (named pipes are the same as this), but Microsoft has weird and vague APIs for that, whereas Winsock is well defined/supported.


Hey, I didn't say it Neutral. http://forum.cheatengine.org/viewtopic.php?p=2825681#2825681
Back to top
View user's profile Send private message MSN Messenger
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Sun Sep 14, 2008 3:31 pm    Post subject: Reply with quote

I meant "You guys who said it" >>
<<

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
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