Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - starfruitinc

Pages: [1]
1
Network / [SOLVED] Reusing sockets
« on: October 02, 2011, 12:41:27 am »
I found the problem. You are right Laurent, it is a problem regarding to the IRC protocol, it does not like \0 at the end of every transmission. A simple -1 to the second argument of the Send function fixes the problem.

Thank you for your help :D

2
Network / [SOLVED] Reusing sockets
« on: October 01, 2011, 08:28:05 pm »
Whoops!
The connectToServer function
Code: [Select]

void connectToServer(sf::SocketTCP &Client) {
    if (Client.Connect(6667, "irc.freenode.org") != sf::Socket::Done) {
        cout << "Error 1" << endl;
    }
    cout << "No Error 1" << endl;
}

3
Network / [SOLVED] Reusing sockets
« on: October 01, 2011, 01:21:06 am »
Code: [Select]
void sendAndRecv(void * UserData) {

    sf::SocketTCP* Client = static_cast<sf::SocketTCP*>(UserData);
    char Buffer[1024];
    std::size_t Received;
    char * buf2;

    //while (Received > 0) {
    for (int i = 0; i < 2; i++) {
    Client->Receive(Buffer, sizeof(Buffer), Received);
    Buffer[Received] = '\0'; //Nulling the last+1 cell
    cout << Buffer;
    }


    char getpage[] = "NICK lmno \n\rUSER lmno 0 * :lmno\n\rJOIN #mytest\n\rPRIVMSG #mytest :qwertyuiop\0";
    Client->Send(getpage, sizeof(getpage));



    char message[] = "PRIVMSG #mytest :La-di-da\n\r";
    while (1) {

        Client->Receive(Buffer, sizeof(Buffer), Received);
        Buffer[Received] = '\0'; //Nulling the last+1 cell
        cout << Buffer <<endl;

        if (strstr(Buffer, "ha!")) {
            Client->Send("ABCDEFG", (size_t)7); //These don't seem to work...
            Client->Send(message, sizeof(message));
            Client->Send(message, sizeof(message));
            Client->Send("ABCDEFG", (size_t)7);
            cout << "ha! triggered" << endl;
        }



        if (strstr(Buffer, ":+i")) {

            char joinchan[] = "JOIN #mytest\n\r\0";
            Client->Send(joinchan, sizeof(joinchan));
            cout << "Sent" << endl << joinchan <<endl;
        }
    }
}

int main() {
    sf::SocketTCP Client;

    connectToServer(Client);

    sf::Thread Thread(&sendAndRecv, &Client);
    Thread.Launch();
}



TCPSocket is passed thru void * UserData, as this is part of a thread.

4
Network / [SOLVED] Reusing sockets
« on: September 30, 2011, 09:09:43 am »
Hmm... I'm using commands that I have tested in telnet. I think there may be something wrong with the sockets because the IRC server would give verbose errors if you typed something wrong. I know this because some of the char arrays (somehow) are not sanitized and send accented characters, which the IRC server would then respond "Unknown Command"

5
Network / [SOLVED] Reusing sockets
« on: September 30, 2011, 05:33:11 am »
Hello everyone,

I have a problem with TCP sockets. I can only get the socket to send once, then all calls to Send() afterward don`t work.

Code: [Select]
sf::SocketTCP* Client = static_cast<sf::SocketTCP*>(UserData);
    char Buffer[1024];
    std::size_t Received;
    char * buf2;


    for (int i = 0; i < 2; i++) {
    Client->Receive(Buffer, sizeof(Buffer), Received);
    Buffer[Received] = '\0'; //Nulling the last+1 cell
    cout << Buffer;
    }

    cout << "End of Recv" << endl;

    char getpage[] = "NICK lmno \n\rUSER lmno 0 * :lmno\n\rJOIN #mytest\n\rPRIVMSG #mytest :qwertyuiop\0";
    Client->Send(getpage, sizeof(getpage)); //This one works

    char message[] = "PRIVMSG #mytest :La-di-da\n\r\0";
    while (1) {

        Client->Receive(Buffer, sizeof(Buffer), Received);
        Buffer[Received] = '\0'; //Nulling the last+1 cell
        cout << Buffer <<endl;

        Client->Send(message, sizeof(message)); // This one does not
        cout << "Sent ladida" << endl;
 




    }


Help is very much appreciated.

edit: I tried out something new, and it works, but it has a useless Send()
Code: [Select]
sender(*Client);
I put this in the while loop
Code: [Select]
void sender(sf::SocketTCP Client) {
    char pong[1024];
    memset (pong, '0', (size_t)1024);
    strcpy(pong, "PRIVMSG #mytest :qwerty");
    //strcat(pong, ping);
    strcat(pong, "\n\r");
    cout << pong << endl;

    Client.Send(pong, sizeof(pong));
    Client.Send(pong, sizeof(pong));

    char msg[128];
    strcpy(msg, "PRIVMSG #mytest :La-Di_da\n\r");
    Client.Send(msg, sizeof(msg));
    cout << "Sent from sender" << endl;
}


The extra Send() must be there to work. Does anyone know why?

Thanks,
SFI

6
Network / Recv Loop
« on: September 29, 2011, 08:31:47 am »
Hello again everyone,

I have a question about how to operate a recv loop. I am making an IRC client and I would like to receive the first few messages, then send in credentials then continue receiving and sending.

Code: [Select]
void ServerHandler::connectToServer() {

    if (Client.Connect(6667, "irc.freenode.org") != sf::Socket::Done) {
        cout << "Error 1" << endl;
    }
    cout << "No Error 1" << endl;
}

void ServerHandler::sendAndRecv() {
    char Buffer[128];
    std::size_t Received;
    for (int i = 0; i < 2; i++) {
    if (Client.Receive(Buffer, sizeof(Buffer), Received) != sf::Socket::Done)
    {
        cout << "Error 2" << endl;
    }
    cout << Buffer << " " << Received <<endl;
    }
    cout << "End of Recv" << endl;

    char getpage[] = "NICK testing \n\rUSER testing 0 * :Testing";
    if (Client.Send(getpage, sizeof(getpage)) != sf::Socket::Done)
    {
        cout << "Error 1.5" << endl;
    }


    for (;;) {
    if (Client.Receive(Buffer, sizeof(Buffer), Received) != sf::Socket::Done)
    {
        cout << "Error 2" << endl;
    }
    cout << Buffer << endl;
    }

}

The problem with this code is that the first recv loop doesn't terminate for a while then abruptly terminates, moving on to the send bit. The second problem is that the socket does not send properly, as it doesn't get any reply, instead terminating the connection. I have already tested the command in telnet, so I know it works. Can anyone tell me what I did wrong?

I also have a few questions. What does sf::Socket::Done do? How do I make this socket be able to receive and send at irregular intervals (Such that it doesn't know when it will be receiving, and it will be sending at around 5-25 strings/second)

Edit: I found out what was the first problem, the IRC server sends 3 lines then waits for the credentials, but the client is also waiting for more... I changed the loop to only loop thru 2 times

Edit 2: I fixed the first recv loop, I'm not sure how it happened but now that problem is not there anymore.

Thanks

7
General / Slow Rendering in SFML
« on: September 29, 2011, 08:16:48 am »
It works very well, thank you very much for your help!

I'm using the output mainly for debugging right now, and I'm keeping a lot of verbose info on. I want it to run at full speed because it is a real time application. I will be removing the couts later.

8
General / Slow Rendering in SFML
« on: September 18, 2011, 06:52:51 pm »
Wow. std::cout is VERY slow. I removed all lines with std::cout and there is a definite boost to the performance. Thank you very much :D

Is there a better way to output to the console without cout?

9
General / Slow Rendering in SFML
« on: September 18, 2011, 06:16:40 pm »
Hello everyone,

I have been playing around with SFML for a game I am designing, but I came across a problem, of which I am unable to determine if it is the result of just my poor coding or if SFML is designed to be called a different way.

Currently, I have a class called Module and it is a container for some variables and a Sprite.

Code: [Select]

class Module {
    public:
        sf::Sprite s_module;
        std::vector<Module> children;
        void addModule();
        void moveFromSpeed(float, float);
        void drawAll(sf::RenderWindow &);
        void setImage(sf::Image & i_module);
};


Here are the methods

Code: [Select]
void Module::drawAll(sf::RenderWindow & App) {
    cout << "Drawing Self\t" << children.size() << " Children" << endl;
    App.Draw(s_module);
    cout << "Drawing Children" << endl;
    for (int i = 0; i < (int)children.size(); i++) {
        children[i].drawAll(App);
    }
}

void Module::addModule() {
    children.push_back(Module());
}

void Module::setImage(sf::Image & i_module) {

    //Set Sprite
    s_module.SetImage(i_module);
    s_module.SetBlendMode(sf::Blend::Alpha);
    s_module.SetPosition(x, y);
}

void Module::moveFromSpeed(float tvelx, float tvely) {
    //Uses the speed variables to move the ship
    x += tvelx;
    y += tvely;
    s_module.SetPosition(x,y);
    for (int i = 0; i < (int)children.size(); i++) {
        children[i].moveFromSpeed(tvelx, tvely);
    }
}


When I add Module classes to children, it slows down considerably. Around 30 children, it slows to maybe 5-10 fps.

Input is appreciated.

Thanks

Pages: [1]
anything