I suggest implementing the real thing first, before trying a simulation. If you don't understand what kind of functionality you need to make it work, there is no point to write a simulation.
Depending on what kind of network you're thinking of, try google to find some code examples.
Once you know what you need, write an (interface) class that provides all the functions that you need, and then derive an implementation class from it that overrides these functions with simulated behavior. How this behavior should look like depends on what you want to simulate.
Here's a basic design in C++:
#include <iostream>
#include <string>
class NetworkBase {
public:
virtual ~NetworkBase() {}
virtual int connect(const std::string& address) = 0;
virtual int send(const std::string& message) = 0;
virtual std::string receive() = 0;
virtual int disconnect() = 0;
};
class NetworkSimulation : public NetworkBase {
private:
int state_;
std::string address_;
public:
NetworkSimulation() : state_(0) {}
virtual ~NetworkSimulation() {}
virtual int connect(const std::string& address) {
if (address.empty())
return -1; address_ = address;
state_ = 1;
return 0; }
virtual int send(const std::string& message) {
std::cout << "Sending new message to " << address_ << ": " << message<< std::endl;
return (int)message.size();
}
virtual std::string receive() {
std::string msg;
std::cout << "Reading message from " << address_ << std::endl;
std::getline(std::cin, msg);
std::cout << "Message received from " << address_ << ": " << msg << std::endl;
return msg;
}
virtual int disconnect() {
if (state_ == 0)
return -1; address_.clear();
state_ = 0;
return 0; }
};
int main()
{
NetworkBase* my_network = new NetworkSimulation;
std::string address("there");
int error = my_network->connect(address);
if (error != 0) {
std::cout << "Not connected to " << address << std::endl;
}
else {
int msg_size = my_network->send("Hello");
if (msg_size == 0) {
std::cout << "Error sending message to " << address << std::endl;
}
std::string msg = my_network->receive();
std::cout << "Message received from " << address << ": " << msg << std::endl;
error = my_network->disconnect();
if (error != 0) {
std::cout << "Error disconnecting from " << address << std::endl;
}
}
delete my_network;
return 0;
}