Skip to content

easy socket interfaces for ipv4,ipv6 acrossing windows and linux

License

Notifications You must be signed in to change notification settings

adfansong/easy_socket

Repository files navigation

easy_socket

easy socket c++ interfaces, support ipv6 only, support windows, linux, android, ios.

change log

More details and upgrade guides can be found in the CHANGELOG.

quick start

server

#include "Socket.h"
EASY_NS_USING;

int port = 9191;

Socket s;

s.on(sListening, ([](void* p)->void{
	EASY_LOG("Listening..");
}));

s.on(sConnection, [&s](void* p)->void{
	EASY_LOG("Connection..");

	Socket *ps = (Socket*)p;
	ps->send("Hello, this is server!");

	ps->on(sData, [](void* p)->void{
		Buffer *buffer = (Buffer*)p;
		if (buffer) {
			EASY_LOG("Data: %s", buffer->toString());
		}
	});

	ps->on(sClose, [&s](void *p)->void {
		EASY_LOG("Connection closed");
	});
});

s.on(sError, [](void*)->void{
	EASY_LOG("Error..");
});

s.listen(port, 0);

EASY_LOG("start update..");
for (;;) {
	s.update();
}

client

char ip[] = "127.0.0.1";
int port = 9191;

Socket s;

s.on(sConnected, [&s](void*)->void{
	EASY_LOG("Connection..");
	s.send("Hello, this is client!");
});

s.on(sError, [](void*)->void{
	EASY_LOG("Error..");
});

s.on(sData, [](void* p){
	Buffer *buffer = (Buffer*)p;
	if (p) {
		EASY_LOG("Data: %s", buffer->toString());
	}
});

s.on(sClose, [](void *p)->void {
	EASY_LOG("Connection closed.");
});

s.connect(port, ip);

EASY_LOG("start update..");
for (;;) {
	s.update();

	if (s.isClosed()) {
		break;
	}
}


About

easy socket interfaces for ipv4,ipv6 acrossing windows and linux

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published