Skip to content

Commit

Permalink
Update socket.md
Browse files Browse the repository at this point in the history
  • Loading branch information
skiff authored Jun 25, 2021
1 parent 3fcd1bd commit abfc62e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/socket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Sockets

### TCP Socket
```
void tcp_example()
{
libpsutil::network::socket* net = new libpsutil::network::socket("1.2.3.4", 1234);
if(net->connect())
{
std::string send_data = "111111111111111111";
net->send(send_data.data(), send_data.length();
char recv_data[100];
net->receive(recv_data, 100);
}
net->close();
delete net;
}
```

### UDP Socket
```
void udp_example()
{
libpsutil::network::socket* net = new libpsutil::network::socket("1.2.3.4", 1234, libpsutil::network::socket_type::SOCKET_TYPE_UDP);
if(net->connect())
{
std::string send_data = "111111111111111111";
net->send(send_data.data(), send_data.length();
char recv_data[100];
net->receive(recv_data, 100);
}
net->close();
delete net;
}
```

0 comments on commit abfc62e

Please sign in to comment.