#include <iostream>
#include <cstdlib>
#ifdef CCXX_NAMESPACES
using namespace std;
#endif
class myTCPSocket : public TCPSocket
{
protected:
public:
};
myTCPSocket::myTCPSocket(
InetAddress &ia) : TCPSocket(ia, 4096)
{
cout << "binding segsize: " << getSegmentSize() << endl;
}
{
cout << "accepting from: " << ia << ":" << port << endl;;
return true;
}
int main(int argc, char *argv[])
{
int i;
TCPStream tcp;
addr = "255.255.255.255";
cout << "testing addr: " << addr << ":" << 4096 << endl;
addr = "127.0.0.1";
cout << "binding for: " << addr << ":" << 4096 << endl;
Thread::setException(Thread::throwException);
try {
myTCPSocket server(addr);
while(server.isPendingConnection(30000)) {
tcp.connect(server);
tcp << "welcome to " << addr << "; segment size=" << tcp.getSegmentSize() << endl;
tcp << "connected from " << tcp.getPeer(&port) << endl;
if(tcp.isPending(Socket::pendingInput, 2000)) {
tcp >> i;
tcp << "user entered " << i << endl;
}
tcp << "exiting now" << endl;
tcp.disconnect();
}
}
catch(SockException& e) {
cout << e.getString() << ": " << e.getSystemErrorString() << endl;
exit(-1);
}
cout << "timeout after 30 seconds inactivity, exiting" << endl;
return 0;
}
#define InetAddress
Definition: address.h:75
#define InetHostAddress
Definition: address.h:76
unsigned short tpport_t
Transport Protocol Ports.
Definition: address.h:86
Network addresses and sockets related classes.