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

Pages: 1 [2] 3 4
16
Network / Remove Output Messages?
« on: January 17, 2009, 04:28:36 pm »
Ah. Good to know this. Never saw it before...

17
Network / Remove Output Messages?
« on: January 17, 2009, 01:59:46 pm »
Not with any C++-Standard-Functions or something like that, AFAIK. I think you could either redirect C "stderr" via freopen() or you could redirect the underlying (system dependent) objects.
But for logging, you normally use clog instead of cerr.
My problem is, that MY cerr output will be redirected, too.

18
Network / Remove Output Messages?
« on: January 16, 2009, 06:20:27 pm »
I'm quite annoyed by SFMLs messages on failed Connections or on failure to close sockets.
I don't think it is the work of a portable library to warn the user about such things, for he should not be interested in them - and especially for the network, there are many reasons for a Socket failing to close or to accept an incoming connection, not always assoziated with the work of the programmer. Furthermore, the warnings can not be internationalized - there are a lot of reasons for not using the console output (especially for the network classes, warnings on missing images for example are okay). You might deactivate them for example when NDEBUG is defined.

19
General / How to get it working with Ubuntu and Code::blocks.
« on: January 12, 2009, 11:54:14 pm »
Hu... yeah... I did, in fact, tell you how to change the current working directory... =)
"cd Desktop/sfml" should work... (with the latest SVN-Sources, where the Directory is simply called sfml)...
Another way would most probably be:
make -C Desktop/sfml-1.4 (or how the directory is named)


Something important about Linux paths:
A path starting with '/' is considered a GLOBAL path (because / is the root directory).
So /Desktop/ and Desktop/ differ - there is no directory called Desktop in / (at least this would not be very usual), but the second path, not starting with a slash, thereby a local path (relative to the current working directory), is equal to ./Desktop, what is exactly what you want here.

20
General / How to get it working with Ubuntu and Code::blocks.
« on: January 11, 2009, 03:32:09 pm »
Okay...
I suggest:
You download the latest SVN-Code from the repository (Download GNU Tarball option).
You just extract the .tar.gz-File (should work with the ubuntu GUI "Extract here" option).
Then you open a terminal/console, and go to that directory (if you downloaded the thing to your desktop, this might be done with "cd Desktop/sfml".)
Then, you type "make" (it will try to compile SFML).
It is great if that works, but there might be some errors (because you are lacking some of the dependencies), so you have to download the missing packets (libopenal(-dev), libsndfile(-dev), ...) via apt-get or, would be easier for a beginner, via synaptic, until there are no more errors (guessing the right packet might be a bit complicated).
If "make" runs without errors (all dependencies are ok), then you simply type "sudo make install" to install SFML. This should be all.

21
Network / Packet Send - Fragmentation?
« on: December 19, 2008, 10:34:53 pm »
Some packets are not received, though they should be... they are sent properly and via LAN, it works exactly as supposed...

22
Network / Packet Send - Fragmentation?
« on: December 19, 2008, 09:23:02 pm »
Hey, I just tested my server/client thingy via LAN - and it works, PERFECTLY.
Now, this might be kinda strange, but is it possible that SFML-TCP-Sockets have problems with Loopback?? Maybe because there is no measurable delay between sending and arriving?

23
Network / Packet Send - Fragmentation?
« on: December 19, 2008, 08:44:28 pm »
Maybe there is some other bug in this code, that is not in my real server code... i don't know, but it seems to fail more often than the real server...

There is something else, preventing compilation of the Network lib (easy to fix, but you probably should fix it):
The include <cstring> (on my platform (newest g++, ubuntu linux 64-bit)) is missing - you may not need it in windows with VCC or Mingw, but with me, memcpy/memset et cetera are not defined without it. So I had to add #include <cstring> to IPAddress.cpp, Packet.cpp and so on...

24
Network / Packet Send - Fragmentation?
« on: December 19, 2008, 04:12:33 pm »
So it would be nice to have some uncommented ~1200 lines for the whole server depending on some libs that will be kind of pain in the ass to compile on windows... not so sure...

This code is the part of the code without those dependencies and it is the part that fails...

I will fix the code so that you can copy/paste it...

25
Network / Packet Send - Fragmentation?
« on: December 19, 2008, 03:10:13 pm »
Well... I think I can try.
Trying to keep it short I omit some error checks et cetera...
Server (C&P should now be possible):
Code: [Select]


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

using namespace sf;
using namespace std;

struct connection
{
       sf::SocketTCP socket;
       sf::Clock timeout;
       sf::IPAddress ip;
       sf::Packet data;
       bool operator==(const connection& other) const;
};

class ConnectionManager
{
     private:
          sf::Selector<sf::SocketTCP> sockets;
          std::vector<connection> connections;
          sf::SocketTCP listener;
      public:
          ConnectionManager();
          ~ConnectionManager();
          void run();
};

bool connection::operator==(const connection& other) const
{
        return (socket == other.socket && ip == other.ip);
}

ConnectionManager::ConnectionManager()
{
       listener.Listen(4223);
       listener.SetBlocking(false);
       sockets.Add(listener);
}

ConnectionManager::~ConnectionManager()
{
       for(int i = 0; i < connections.size(); i++)
             if(connections[i].socket.IsValid()) connections[i].socket.Close();
       listener.Close();
}

void ConnectionManager::run()
{
while(1)
{
       for(vector<connection>::iterator i = connections.begin(); i < connections.end(); i++)
       {
              if(!(*i).socket.IsValid())
              {
                    i = connections.erase(i); i--;
              }
              if((*i).timeout.GetElapsedTime() > 1.5)
              {
                    i->socket.Close();
                    i = connections.erase(i); i--;
              }
       }
       unsigned int ready = sockets.Wait(0.005f);
       for(unsigned int i = 0; i < ready; i++)
       {
               SocketTCP sock = sockets.GetSocketReady(i);
               if(sock == listener)
               {
                      SocketTCP newcon;
                      IPAddress ip;
                      if(listener.Accept(newcon,&ip) == Socket::Done)
                      {
                             sockets.Add(newcon);
                             connection c;
                             c.socket = newcon;
                             c.socket.SetBlocking(false);
                             c.ip = ip;
                             c.timeout = Clock();
                             connections.push_back(c);
                      }
               }
       }
  for(vector<connection>::iterator i = connections.begin(); i < connections.end(); i++)
  {
          if(i->socket.IsValid())
          {
                  Socket::Status state;
                  state = i->socket.Receive(i->data);
                  if(state == Socket::Done &&
                  i->data.GetDataSize() == 4)
                  {
                      cout << "packet received successfull" << endl;
                      //handle packet (omitted)
                  }
                  if(state == Socket::NotReady) continue;
          }
       }
}
}

int main()
{
ConnectionManager c;
c.run();
return 0;
}



Client:

Code: [Select]

   SocketTCP ssock;
   if(ssock.Connect(4223,"127.0.0.1",1.f))
   {
      Packet p;
      p << (Uint32)0x80A1DA12;
      ssock.Send(p);
      ssock.Close();
   }
   return 0;


Cause I rewrote the code to post it here there might be syntax flaws or so, but I think it will reproduce the error on my platform.

26
Network / Packet Send - Fragmentation?
« on: December 19, 2008, 11:01:55 am »
Yes, it is the TCP checksum... but I don't think that this is the bug (because it seems to be wrong even for packets sent/received correctly) ... the data is sent and seems to be valid... but somehow... the server does not receive it. I am giving a timeout of 1.5 seconds to receive the packets (I am using non-blocking sockets to receive)...
And using the loopback... and still, this 4-byte-packet is not received and Receive returns with NotReady...

27
Network / Packet Send - Fragmentation?
« on: December 19, 2008, 12:22:38 am »
Nope, this is not working.
The packets are not coming through, but it now works far more often than before - maybe 50% of the cases.

It just seems like a simple client like this:

Code: [Select]

        SocketTCP ssock;
if(ssock.Connect(4223,"127.0.0.1",1.f))
{
Packet p;
p << (Uint32)0x80A1DA12;
ssock.Send(p);
p.Clear();
ssock.Receive(p);
cout << p.GetDataSize() << endl;
ssock.Close();
}
return 0;

is sending packets with a length of 0 sometimes.

Well... I checked this with wireshark. The packets are not sended empty, but with wrong TCP checksum... this is most probably a bug, isn't it? There are 2 data packets send from client to server, the first one I think contains the length (0x4), and the second one with 4 bytes of data. But... they both have the same (both times wrong) checksum... uh? Or is a checksum of 0xfe2c normal and used always by SFML ?!
Hmm, well... somehow this is true also for connections that are working... strange.

28
Network / Packet Send - Fragmentation?
« on: December 17, 2008, 08:37:21 pm »
I think I am using the SVN version, but I will try to update all files.

29
Network / Can I use client socket grabbed by selector to send data?
« on: December 17, 2008, 12:24:22 am »
This is an important question, but I think it should be possible to store a socket into a container class...

30
Network / Packet Send - Fragmentation?
« on: December 17, 2008, 12:06:32 am »
Hmmm...
I'm encountering several problems with the SocketTCP class:
In the moment, I am sending data via loopback. The client uses a blocking socket to send 4 byte of data in a sf::Packet. The server does not use a blocking socket, and he can't do so. (Well, this is REALLY strange, because a blocking socket absolutely blocks even if there is no data left, if the client side does not use sf::Packets (for example, if I try to connect to the socket with netcat). A stable server can not make any assumptions about the thingys connecting to it and about the amount of data sent, so it is not possible to use a blocking socket for me here.)

Now, the problem is, that if I try to receive the 4-byte-packet sent by the client, this sometimes (but rarely) works, but mostly it refuses to work. I am using a sf::Selector to announce me if any sockets are ready to read, but if I try to read from them, the length of the packet is 0.
The whole thing works like the tutorial:

1. Set up a listener, add it to a selector, and wait on this selector.
2. There are some sockets ready to read. If the socket is the listener, accept the connection, and, if successfull, add the new socket to the selector.
3. Else, try to read from the socket. If there is no data (packet length == 0), put the socket into a map together with a Clock to give the socket 1 second for the data of the data to arrive (assuming that the selector will alert me if this happens).
4. If there is data, process it.

... Step 4 is never reached. The length of the packet stays 0, even if the selector thinks there should be data to read.

And no, the tutorial also does not work. The client immediately sees "Press enter to exit...". But the connection is established (the server displays "Client connected ! (127.0.0.1)" and the loopback interface is working.

Pages: 1 [2] 3 4
anything