I have a sockets projects using tcp/ip and it is structured like this:
class Socket {
int desc;
Socket(); // create socket here
}:
class TCPSocket: public Socket {
public:
int send();
int recv();
};
class ClientSocket: public TCPSocket {
public:
void connect();
};
class ServerSocket: public Socket {
public:
void bind();
void listen():
TCPSocket* accept();
};
My question is,it is posible to create in the same program a ServerSocket to listen for incoming connections,and a ClientSocket to client to a specific address:
int main()
{
ServerSocket s;
s.Bind();
s.Listen();
while(true)
{
TCPSocket* sock = s.Accept();
//code here
ClientSocket c;
c.Connect(address_here, port_here);
}
return 0;
}
Because everytime i do this it doesnt connect,it waits for a few seconds,and then Connect() gives me error with the description "No Error".If i create only a ClientSocket and connect directly,it works.So can someone help me understand what is wrong,and how to resolve this.
Thanks in advanced.