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

Pages: [1]
1
Network / Strange client outputs...
« on: July 02, 2010, 11:46:19 pm »
Quote from: "TheMagician"
It's the c_str() that's appending the null termination:

Quote
c_str(): Generates a null-terminated sequence of characters (c-string) with the same content as the string object and returns it as a pointer to an array of characters.

A terminating null character is automatically appended.

http://www.cplusplus.com/reference/string/string/c_str/


You can use data() to return const char* string without null termination:

Quote
data(): Returns a pointer to an array of characters with the same content as the string.

Notice that no terminating null character is appended

http://www.cplusplus.com/reference/string/string/data/


And length() will return size_t length of the string.

So replace

Code: [Select]
mainSocket.Send(buffer.c_str(),sizeof(char) * (buffer.size() + 1));

With

Code: [Select]
mainSocket.Send(buffer.data(), buffer.length());


At the time I read this, I had already found a solution (a workaround, that is).
I was perfectly sure the terminating null was the problem, and my alternate method of getting in contact with the server showed this.

But I do thank you, Magician. I'm no longer required to use the (quite ugly) workaround.

2
Network / Strange client outputs...
« on: June 27, 2010, 04:30:04 am »
'sup. ;)

Me and my friend recently began programming an IRC-client/bot. Everything went quite fine, until we realized that the server suddenly stopped reading our messages.

Well, I figured, we must've done something wrong. So I set up a sever-program and connected the client with it. After some foul debugging, I discovered that our \r\n (CR+LF) at the end of every sf::SocketTCP::Send() got ouputed as something more like \n\0. A newline and a nul, that is.
This is probably why the server kept ignoring our messages.

I've been able to recreate the situation with a few lines of code. It would be wonderful if anyone could review it and find any particular errors that might be the cause of this strange behaviour.

Code: [Select]


#include <SFML/System.hpp>
#include <SFML/Network.hpp>
#include <iostream>


int main()
{

    sf::IPAddress ip("127.0.0.1");
    sf::SocketTCP mainSocket;
    mainSocket.Connect(6667,ip.ToString());

    std::string buffer("This is a test.\r\n");
    mainSocket.Send(buffer.c_str(),sizeof(char) * (buffer.size() + 1));
    std::cout << "Sent the stuff. Terminating...";


    return 0;
}



As of why I am using std::string as a buffer, It's necessary to get what I want in the real troublemaking app. I certainly hope it's not the cause.
(In fact it can't be. I see the same thing when using a non-converted char buffer)

Another thing that might be relevant, is that my home-made server (the one I used for testing and debugging) can't seem to read the whitespaces as regular 0x20 chars. However, when using a client made with another library, it can.

Like I said, I hope someone better than I can solve my issue.
Thanks in advance,
Fr4sbokz

Pages: [1]
anything