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

Pages: [1]
1
Okay, thanks for the quick answers.

2
Hm, I see, but even after calling listen() before reuse(), I still cannot bind to the port the second time round - do I need to somehow set SO_REUSEADDR after creation but before binding?
So I probably have to create my own sockets?

3
Hi,

I've got the same problem with my application.

I already tried to implement SO_REUSEADDR like written above but to no avail:

Code: [Select]

class relistener : public sf::TcpListener
{
public:
    void reuse() ;
};

void relistener::reuse()
{
        char reusec = 1;
        setsockopt( getHandle(), SOL_SOCKET, SO_REUSEADDR, &reusec, sizeof( reusec ) );
}

int gameloop()
{
/*...*/

        BINDPORT = 53123;
relistener listener;
listener.setBlocking(false);
std::array<sf::TcpSocket,6> socks;

/*...*/

        unsigned playercount=0;
listener.reuse();
listener.listen(BINDPORT);
while(mgame.init)
{
if(listener.accept(socks[playercount]) == sf::Socket::Done)
{
std::cout << "accepted player" << std::endl;
playercount++;
socks[playercount].setBlocking(false);
}
handle_commands(mgame,socks); // lets one of the players set mgame.init to false
}
listener.close();

/*...*/

return 0;
}

int main()
{
while(true)
{
gameloop();
}

return 0;
}

When the gameloop is finished and tries to rebind a new listener, it tells me that it failed to bind and according to netstat, the port (53123 in this case) is still in TIME_WAIT.
I'm on Linux 3.10.3-1 (Arch Linux) if that matters.

I read about SO_REUSEPORT somewhere, but I can't find a header that implements it.

I hope somebody can help me ;)

4
General / Ubuntu 10.10 no debug libraries?
« on: March 05, 2011, 09:26:32 pm »
yeah, I just discovered that. I just encountered problems when porting my code from windows to linux. Thanks anyways.

5
General / Ubuntu 10.10 no debug libraries?
« on: March 05, 2011, 01:20:46 pm »
Hello!

I have a problem using SFML 1.6 under Ubuntu 10.10. For some reasons I do not have the debug libraries. I use Code::Blocks 10.05 with gcc and linked the libraries using -lsfml-system-d etc, but the linker can't find them. I tried installing sfml from the ubuntu repository as well as compiling it from source myself (DEBUGBUILD=yes), to no avail.

What am I doing wrong?

6
Network / Problem with UDP Sockets
« on: January 25, 2011, 01:21:55 pm »
Generally, the Receiving and Sending using UDP Sockets works. I added a test send/receive to the beginning of the Threads and it all worked fine.

The Problem seems to be that nothing is received at all, i.e. no packet ever arrives, the function never goes past the Receive(), since it's in blocking mode. It doesn't matter how often I send the packet.
I've got it working using Selectors now, but as I said, would still be nice to know why it didn't work using UDP.
Normally I would assume it's an error somewhere completely unrelated in the program logic (like maybe filling/receiving the packets wrongly, binding wrong ports etc.), but since it works when I simply exchange UDP with TCP and leave everything else exactly the same, that does not seem to be the case.
Unless there arises a problem if I keep a TCP and a UDP Socket open at the same time? (using different ports)

7
Network / Problem with UDP Sockets
« on: January 25, 2011, 01:21:24 am »
I thought that wouldn't be a problem, because as far as I understand, the port that is called in SocketUDP::Receive is simply filled with the port of the incoming connection.
Is that correct?

8
Network / Problem with UDP Sockets
« on: January 24, 2011, 11:46:47 pm »
You're right, I didn't think of that, very new to SFML. Thanks!
Still, would be nice to know why it doesn't work with the UDP Sockets.

9
Network / Problem with UDP Sockets
« on: January 24, 2011, 06:25:12 pm »
Hi!

I've got a problem using UDP Sockets to send data from one Thread to another.

A little background: I'm trying to program a game client and usually I'm using TCP Sockets for the communication. However, at this particular point in time, I need to send a request to all players and work with whatever comes back first.
I think the only way to do that with TCP Sockets is to start an extra thread for every player, am I correct? Because that seemed a bit excessive, I thought of using UDP Sockets to wait for connections and then take whatever Packet I receive first on the given port.

However, the sent packages never arrive.

Some code:

Player (Client) Side:
Code: [Select]

sf::Packet pack2;
//....
sf::SocketUDP udp_sock;

if(udp_sock.Send(pack2, server_ip, 3456)==sf::Socket::Done)
{
   std::cout << std::endl << "sent UDP Button " << clickpos << " to " << server_ip << ":3456"  << std::endl;
}
else
{
   std::cout << std::endl << "Sending of UDP Button failed" << std::endl;
}


Server Side:
Code: [Select]

sf::SocketUDP udp_sock;
if(!udp_sock.Bind(3456))
{
   std::cout << std::endl << "Error binding UDP Socket to port " << udp_sock.GetPort() << std::endl;
}
else
{
   std::cout<<std::endl<<"Bound Socket to port 3456" <<std::endl;
}
//.....

sf::Packet pack;
sf::IPAddress addy;
unsigned short porty;
if(udp_sock.Receive(pack,addy,porty)==sf::Socket::Done)
{
   std::cout << std::endl << "Received UDP Button From " << addy << ":" << port << " with " << pack.GetDataSize() << "B" <<std::endl;
}
else
{
   std::cout << std::endl << "Receiving of UDP Button Failed" << std::endl;
}


I tried using TCP Sockets instead of UDP Sockets at those points (simply sending/receiving to/from player 1 only) and it worked fine.

As I said at the beginning, the the Client/Server side are currently simply two different threads (like a listening Server) for testing purposes.

If anybody has an idea why this doesn't work, it'd be greatly appreciated :)
I suppose the error could lie elsewhere in the code, but it's >15k lines as of now, so if there are some "standard" errors I could look for, it'd make my life much easier...

*edit*
Thinking that maybe I didn't receive anything because the Client Thread sent the packet before I was waiting for it in the Server Thread, I put the Send() command in an infinite loop, but still nothing arrived.

Thanks

10
Network / Program crashes with packet & selector usage
« on: December 27, 2010, 11:48:03 pm »
Well, that was stupid. It seems I had sfml 1.5 from the ubuntu repository installed via aptitude and, separately, sfml-1.6 compiled from source. somehow that led to conflicts, I randomly checked aptitude and saw 1.5 under installed so I deleted it and now it works like a charm.
Thanks for the fast responses btw.

11
Network / Program crashes with packet & selector usage
« on: December 27, 2010, 07:58:24 pm »
nope, 32bits
I'll try to install 1.5 from the website and then from the repositories once i get internet again. I'll report back with results.

12
Network / Program crashes with packet & selector usage
« on: December 27, 2010, 07:47:47 pm »
from the website, the repository only had 1.5.
I'd try the repository but my linux pc doesn't have internet atm (I'm using another laptop right now)

13
Network / Program crashes with packet & selector usage
« on: December 27, 2010, 05:19:34 pm »
Never used gdb before, but here we go.
All I'm getting is:
Code: [Select]

terminate called after throwing an instance of 'std::bad_alloc'
  what(): std::bad_alloc

Program received signal SIGABRT, Aborted.
0x0012d422 in __kernel_vsyscall ()

The line is line 72 in network-selector.cpp
Code: [Select]

Selector.Add(Listener);


Is this what you needed?

*edit*
ran a backtrace too:
Code: [Select]

#0  0x0012d422 in __kernel_vsyscall ()
#1  0x002ac651 in raise () from /lib/tls/i686/cmov/libc.so.6
#2  0x002afa82 in abort () from /lib/tls/i686/cmov/libc.so.6
#3  0x0020652f in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/libstdc++.so.6
#4  0x00204465 in ?? () from /usr/lib/libstdc++.so.6
#5  0x002044a2 in std::terminate() () from /usr/lib/libstdc++.so.6
#6  0x002045e1 in __cxa_throw () from /usr/lib/libstdc++.so.6
#7  0x00204c5f in operator new(unsigned int) () from /usr/lib/libstdc++.so.6
#8  0x0804aedb in __gnu_cxx::new_allocator<char>::allocate (this=0xbffff370, __n=4294967295)
    at /usr/include/c++/4.4/ext/new_allocator.h:89
#9  0x0804a9ac in std::_Vector_base<char, std::allocator<char> >::_M_allocate (this=0xbffff370, __n=4294967295)
    at /usr/include/c++/4.4/bits/stl_vector.h:140
#10 0x0804a30a in _Vector_base (this=0xbffff370, __n=4294967295, __a=...) at /usr/include/c++/4.4/bits/stl_vector.h:113
#11 0x08049ed7 in vector (this=0xbffff370, __x=...) at /usr/include/c++/4.4/bits/stl_vector.h:242
#12 0x08049db4 in SocketTCP (this=0xbffff364) at /usr/local/include/SFML/Network/SocketTCP.hpp:46
#13 0x080498ae in DoServer (Port=2435) at main.cpp:72
#14 0x08049c33 in main () at main.cpp:136


14
Network / Program crashes with packet & selector usage
« on: December 27, 2010, 04:46:32 pm »
Hello,

I'm totally new at using SFML, so I really don't know what could be wrong here.

First of all, I'm using SFML 1.6 on Ubuntu 10.04 lucid with Code::Blocks 10.05 and g++ 4.4.3.

When receiving Packets, I get Segmentation faults and the program crashes (This happens even with the example packet code from the tutorial).
I worked around this by not sending the packets but raw data, using the GetData(),GetDataSize() commands and then Append()-ing the data on receiving.

I also get crashes with calls to std::bad_alloc when using Selector.Add(); again, this also happens in the example code from the selector tutorial.

I'd be grateful if anybody could help.

Pages: [1]