[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getPeer(tpport_t *port) and SocketPort for bound UDPSockets broken?
From: |
Wolfgang |
Subject: |
Re: getPeer(tpport_t *port) and SocketPort for bound UDPSockets broken? |
Date: |
Sat, 27 Dec 2003 22:49:12 +0100 |
User-agent: |
KMail/1.5.4 |
Hello Federico,
well i called getPeer() within pending() . for my test, i did it every time in
pending before calling receive().
i know that datagram works connectionless in comparison to TCP based
streamsockets.
//using SocketPort:
//doesn't return correct peer information for udpsocket
//but works for tcpsockets
void pending(void) {
tpport_t mport; InetHostAddress ia = getPeer(&mport);
cout << "Remote Client: " << ia << ":" << mport << endl;
char buffer[1000]; int dlen; dlen = receive(buffer, 1000);
buffer[dlen] =
'\0';
if (dlen > 0) {
cout << "MySocketPort::pending. so: " << so << "
received: " << dlen <<
"bytes. = " << buffer << endl;
}
else {
cout << "MySocketPort::pending. so: " << so << " dlen
<= 0!: " << dlen <<
endl;
//this is not the best way but for a simple test...
delete this;
}
};
then i did a test with a UDPSocket and called getPeer() after a packet arrived
but before receive().
//explicit server, explicit getPeer() call - this works as it should
pserver = new UDPSocket("127.0.0.1", 12345);
pserver->setPeer("127.0.0.1", 11111);
tpport_t mport; InetHostAddress ia = pserver->getPeer(&mport);
cout << "Remote Client: " << ia << ":" << mport << endl;
dlen = pserver->receive(buffer, 1000); buffer[dlen] = '\0';
if (dlen > 0) { cout << "pserver received: " << dlen << "bytes.
= " <<
buffer << endl;}
furthermore, i could imagine, that socketport does not use UDPSocket::getPeer
but Socket::getPeer(). this would explain the behaviour.
Best regards
Wolfgang
Am Samstag, 27. Dezember 2003 22:38 schrieb Federico Montesino Pouzols:
> Hi, do you see that broken behaviour with UDPSocket before
> receiving any packet on the socket? UDPSocket::getPeer uses the
> 'recvfrom' system call to retrieve the actual current peer the socket
> is receiving from. If no packet has been received so far or is not
> available, recvfrom will return 0. For an UDP socket, the peer is not
> so clearly defined as for a TCP socket. I guess it would be helpful to
> point this out in the SocketPort docs.
>
> On Sat, Dec 27, 2003 at 05:57:55AM +0100, Wolfgang wrote:
> > Hello,
> >
> > when using getPeer(tpport_t *port) in a derived class from SocketPort
> > using a CTOR for a bound UDPSocket, getPeer always returns 0.0.0.0:0
> > (Adress and port eq 0).
> > However when using an explicit UDPSocket, UDPSocket::getPeer works.
> >
> > Doing the same with SocketPort and a bound TCPSocket is not a problem.
> >
> > It seems that this is because UDPSocket overloads getPeer from Socket,
> > which is not the case for TCPSocket. So SocketPort will not call
> > UDPSocket::getPeer but Socket::getPeer (which works for TCPSocket's).
> >
> > Best regards
> >
> > Wolfgang
> >
> >
> >
> >
> >
> >
> > _______________________________________________
> > Bug-commoncpp mailing list
> > address@hidden
> > http://mail.gnu.org/mailman/listinfo/bug-commoncpp