Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,058 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,552 people online right now. Registration is fast and FREE... Join Now!




making a silkroad bot cant connect to game with sockets

 
Reply to this topicStart new topic

making a silkroad bot cant connect to game with sockets

dragonsword1
1 Aug, 2008 - 02:27 PM
Post #1

New D.I.C Head
*

Joined: 2 Feb, 2007
Posts: 21


My Contributions
CODE

#define silk_IP "121.128.133.64"
#define silk_PORT 15779
struct sockaddr_in silkroad;
silkroad.sin_family = AF_INET;
silkroad.sin_port = htons (silk_PORT);
silkroad.sin_addr.s_addr = inet_addr(silk_IP);
memset(silkroad.sin_zero, '\0', sizeof silkroad.sin_zero);
int chk = connect(nuconnector,(struct sockaddr *)&silkroad,sizeof silkroad);
if(chk=-1)
{
cout<<"could not connect"<<endl;
cin>>x;
}
else
{
cout<<"u have connected to silkroad /gg"<<endl;
cin>>x;
}

(this is not the whole code if u want it tell me)
here is the code i used to connect to the game
and when i open the game and open the program it say could not connect (conect error) so if there another thing i should learn please give me tut links or if it can be fixed please tell me how

This post has been edited by dragonsword1: 1 Aug, 2008 - 02:28 PM
User is offlineProfile CardPM
+Quote Post

Hyper_Eye
RE: Making A Silkroad Bot Cant Connect To Game With Sockets
1 Aug, 2008 - 09:51 PM
Post #2

D.I.C Head
**

Joined: 13 Sep, 2007
Posts: 72



Thanked: 4 times
My Contributions
You can use perror() to see why your connect() call failed.

The best guide I have ever seen on this topic would be Beej's Guide.

If I had to venture a guess with only the code posted I would say the socket() call is missing but that could be in the code you didn't post.

This post has been edited by Hyper_Eye: 1 Aug, 2008 - 09:52 PM
User is offlineProfile CardPM
+Quote Post

dragonsword1
RE: Making A Silkroad Bot Cant Connect To Game With Sockets
2 Aug, 2008 - 04:55 AM
Post #3

New D.I.C Head
*

Joined: 2 Feb, 2007
Posts: 21


My Contributions
well here is all the code and there is nothing in the socket the error is in the connect

CODE

#include<iostream.h>
#include<winsock.h>
#include<stdio.h>
#pragma comment(lib, "wsock32.lib" )
#define silk_IP "121.128.133.64"
#define silk_PORT 15779
int main()
{
    /*-------------------some first shit nonsense---------*/
    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
    fprintf(stderr, "WSAStartup failed.\n");
    exit(1);
    }
    /*----------------------now the bot--------------------*/
    int nuconnector;    
    int x;
    struct sockaddr_in silkroad;
    nuconnector = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);  //making the socket  //maybe raw
    if (nuconnector < 0)
    {
        cout<<"cannot establish connection socket creation error"<<endl;
        cin>>x;
        return 0;
    }
    else
    {
        cout<<"socket created.."<<endl;
    }
    silkroad.sin_family = PF_INET;
    silkroad.sin_port = htons (silk_PORT);
    silkroad.sin_addr.s_addr = inet_addr(silk_IP);
    memset(silkroad.sin_zero, '\0', sizeof silkroad.sin_zero);
    int chk = connect(nuconnector,(struct sockaddr *)&silkroad,sizeof silkroad);
    if(chk=-1)
    {
        cout<<"could not connect"<<endl;
        cin>>x;
    }
    else
    {
        cout<<"u have connected to silkroad /gg"<<endl;
        cin>>x;
    }
}

User is offlineProfile CardPM
+Quote Post

Hyper_Eye
RE: Making A Silkroad Bot Cant Connect To Game With Sockets
2 Aug, 2008 - 10:25 AM
Post #4

D.I.C Head
**

Joined: 13 Sep, 2007
Posts: 72



Thanked: 4 times
My Contributions
Use the perror() call on your connect() failure. It will tell you why the connect failed. Pretty much all functions dealing with sockets set error codes on failure and can be printed with perror() (except gethostbyname() which can be checked on Linux with herror().)

CODE
#include <errno.h>

    int chk = connect(nuconnector,(struct sockaddr *)&silkroad,sizeof silkroad);
    if(chk=-1)
    {
        perror("connect");
        cout<<"could not connect"<<endl;
        cin>>x;
    }
    else
    {
        cout<<"u have connected to silkroad /gg"<<endl;
        cin>>x;
    }

User is offlineProfile CardPM
+Quote Post

dragonsword1
RE: Making A Silkroad Bot Cant Connect To Game With Sockets
3 Aug, 2008 - 01:50 PM
Post #5

New D.I.C Head
*

Joined: 2 Feb, 2007
Posts: 21


My Contributions
well i made the perror on the socket command and on the connect command and it say
CODE

socket created..
connect:no error
could not connect

what would it be?
User is offlineProfile CardPM
+Quote Post

Hyper_Eye
RE: Making A Silkroad Bot Cant Connect To Game With Sockets
3 Aug, 2008 - 02:05 PM
Post #6

D.I.C Head
**

Joined: 13 Sep, 2007
Posts: 72



Thanked: 4 times
My Contributions
QUOTE(dragonsword1 @ 3 Aug, 2008 - 04:50 PM) *

well i made the perror on the socket command and on the connect command and it say
CODE

socket created..
connect:no error
could not connect

what would it be?


I see it. It is one of the most common programming mistakes and even a pro will make it. Take a look at my socket issue where I did the same thing:

http://www.dreamincode.net/forums/index.ph...c=33202&hl=
tongue.gif

Anyway...

CODE
-if(chk=-1)
+if(chk == -1)





User is offlineProfile CardPM
+Quote Post

dragonsword1
RE: Making A Silkroad Bot Cant Connect To Game With Sockets
4 Aug, 2008 - 10:58 AM
Post #7

New D.I.C Head
*

Joined: 2 Feb, 2007
Posts: 21


My Contributions
ok thankssssss alot thats a very very silly mistake a hidden one XD
User is offlineProfile CardPM
+Quote Post

Hyper_Eye
RE: Making A Silkroad Bot Cant Connect To Game With Sockets
4 Aug, 2008 - 03:06 PM
Post #8

D.I.C Head
**

Joined: 13 Sep, 2007
Posts: 72



Thanked: 4 times
My Contributions
QUOTE(dragonsword1 @ 4 Aug, 2008 - 01:58 PM) *

ok thankssssss alot thats a very very silly mistake a hidden one XD


No problem. This one gets all of us and most of us will run into it more then once. You feel like an idiot when you realize the problem but that's just the way it goes.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 06:10PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month