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] Connect to a Port?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Wed Jul 16, 2008 1:41 am    Post subject: [C] Connect to a Port? Reply with quote

How can i connect to a port on a website?
I just want to make a connection to my website on port 80.

I googled, but all i found was people with errors. I still looked through the errors, didn't really find any code. So could someone please explain how this is done.
Back to top
View user's profile Send private message MSN Messenger
DoomsDay
Grandmaster Cheater
Reputation: 0

Joined: 06 Jan 2007
Posts: 768
Location: %HomePath%

PostPosted: Wed Jul 16, 2008 1:48 am    Post subject: Reply with quote

http://www.google.com/codesearch

Last edited by DoomsDay on Wed Jul 16, 2008 4:55 am; edited 1 time in total
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: Wed Jul 16, 2008 4:04 am    Post subject: Reply with quote

Code:
bool Running = true;
     int sockfd, newsockfd, portno = 6667, clilen;
     struct sockaddr_in serv_addr, cli_addr;
     pthread_t ClientHandlerThread;

     printf( "\n----------\n" );

     // Create socket
     sockfd = socket(AF_INET, SOCK_STREAM, 0);
     if (sockfd < 0) {
        printf( "Unable to create socket!\n" );
        return 1;
     }

     bzero((char *) &serv_addr, sizeof(serv_addr));

     // Bind socket
     serv_addr.sin_family = AF_INET;
     serv_addr.sin_addr.s_addr = INADDR_ANY;
     serv_addr.sin_port = htons(portno);

     if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
         printf( "Unable to bind socket!\n" );
         return 1;
     }

     while( Running == true )
     {
         // Begin listening
         listen(sockfd,5);
         clilen = sizeof(cli_addr);

         newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *) &clilen);

         // Handle Client
         pthread_create(&ClientHandlerThread, NULL, ClientHandler, &newsockfd);
     }


i handled the client like:

Code:
void *ClientHandler( void* sock )
{
     const char *reply = "\r<center>Test Server</center>\r";
     char buffer[1024];
     int socket;

     memcpy( &socket, sock, sizeof(int) );
     write( socket, reply, strlen(reply) );
     printf( "Connection on socket %i...\n", socket );

     close(socket);
     pthread_exit(NULL);
}


The portno variable at the top defines the port btw.

EDIT: Oh, you want to make the connection..
Back to top
View user's profile Send private message MSN Messenger
oib111
I post too much
Reputation: 0

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

PostPosted: Wed Jul 16, 2008 7:24 am    Post subject: Reply with quote

Code:

#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <iostream>
#pragma comment(lib, "WS2_32.lib")

#define DEFAULT_PORT "80"

int main() {
   struct addrinfo hints, *result, *ptr;
   SOCKET ConnectSocket;
   WSADATA wsaData;
   if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
      std::cout<<"WSAStartup failed with error: "<<WSAGetLastError();
      _getch();
      return 1;
   }
   ZeroMemory(&hints, sizeof(hints));
   hints.ai_family = AF_UNSPEC;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_protocol = IPPROTO_TCP;
   if(getaddrinfo("google.com", DEFAULT_PORT, &hints, &result) != 0) {
      std::cout<<"getadrrinfo failed with error: "<<WSAGetLastError();
      _getch();
      WSACleanup();
      return 1;
   }
   for(ptr = result; ptr != NULL; ptr = ptr->ai_next) {
      ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
      if(ConnectSocket == INVALID_SOCKET) {
         std::cout<<"socket failed with error: "<<WSAGetLastError();
         _getch();
         freeaddrinfo(result);
         WSACleanup();
         return 1;
      }
      if(connect(ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen) != SOCKET_ERROR) {
         break;
      }
      else {
         std::cout<<"connect failed with error: "<<WSAGetLastError();
         _getch();
         freeaddrinfo(result);
         WSACleanup();
         return 1;
      }
   }
   freeaddrinfo(result);
   _getch();
   return 0;
}

_________________


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
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Wed Jul 16, 2008 2:43 pm    Post subject: Reply with quote

thanks oib. Thats awesome. I would +rep you but it says i have to wait like a million seconds -_-
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Sun Jul 20, 2008 10:29 am    Post subject: Reply with quote

Overload wrote:
thanks oib. Thats awesome. I would +rep you but it says i have to wait like a million seconds -_-


+Rep Microsoft because the code he posted is just a slightly changed version of whats posted on the MSDN:
http://msdn.microsoft.com/en-us/library/ms737591%28VS.85%29.aspx

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
oib111
I post too much
Reputation: 0

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

PostPosted: Sun Jul 20, 2008 10:53 am    Post subject: Reply with quote

Yea. I read the tutorial at MSDN, and learned some Winsock, big woop. I remembered the functions and their parameters and the variables I needed and how it worked. Sorry if my code happens to be similar, because well that's how I learned, so it's gonna be similar.
_________________


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
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