| View previous topic :: View next topic |
| Author |
Message |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Thu Sep 11, 2008 3:11 pm Post subject: [Rls] Communication through sockets |
|
|
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 |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Thu Sep 11, 2008 3:29 pm Post subject: |
|
|
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 |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Thu Sep 11, 2008 3:32 pm Post subject: |
|
|
| 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 |
|
 |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
Posted: Thu Sep 11, 2008 3:37 pm Post subject: |
|
|
what is the @ server
WaitForSingleObject(mutexHandle, INFINITE);
doesnt it need
ReleaseMutex before next loop?
_________________
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Thu Sep 11, 2008 3:47 pm Post subject: |
|
|
| 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 |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Sep 11, 2008 5:06 pm Post subject: |
|
|
| 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...
|
|
| Back to top |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Thu Sep 11, 2008 5:52 pm Post subject: |
|
|
| 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 |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Thu Sep 11, 2008 6:05 pm Post subject: |
|
|
Edit:
.credits. kthx
Last edited by slippppppppp on Thu Sep 11, 2008 6:28 pm; edited 1 time in total |
|
| Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
Posted: Thu Sep 11, 2008 6:44 pm Post subject: |
|
|
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 |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Thu Sep 11, 2008 8:21 pm Post subject: |
|
|
| 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 |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Fri Sep 12, 2008 3:34 am Post subject: |
|
|
| 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...  |
'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 . http://forum.cheatengine.org/viewtopic.php?p=2825681#2825681
|
|
| Back to top |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
Posted: Sun Sep 14, 2008 3:31 pm Post subject: |
|
|
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 |
|
 |
|