restructure and add server/client example
This commit is contained in:
28
shared/inc/TcpSocket.hpp
Normal file
28
shared/inc/TcpSocket.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#define AS_DEFAULT_BUFFER_SIZE 0x1000 /*4096 bytes*/
|
||||
|
||||
namespace TcpSocket
|
||||
{
|
||||
|
||||
void setTimeout(int seconds, int sock);
|
||||
|
||||
ssize_t sendt(int sock, const void *bytes, size_t byteslength);
|
||||
|
||||
ssize_t recvt(int sock, void *bytes, size_t byteslength);
|
||||
|
||||
void closet(int sock);
|
||||
|
||||
std::string remoteAddress(sockaddr_in &address);
|
||||
|
||||
int remotePort(sockaddr_in &address);
|
||||
int connectt(const char *host, uint16_t port);
|
||||
|
||||
typedef std::function<void(int sock, sockaddr_in newSocketInfo)> OnNewConnectionCallBack;
|
||||
int listent(const char *host, uint16_t port, OnNewConnectionCallBack callback);
|
||||
|
||||
} // namespace TcpSocket
|
Reference in New Issue
Block a user