ZSocket library – a thin wrapper around BSD socket api.

Wrote a simple socket classes for TCP and UDP with windows and linux compatibility.

Its a very thin wrapper around BSD socket api.

Here is link for ZSocket Library implementation file

ZSocket.h

server.cpp

client.cpp

==========================================================================================

Sample code for TCP & UDP server using ZSocket library
//Compiler version :: g++ (GCC) 4.6.0 20110428 (Red Hat 4.6.0-6)
//g++ server.cpp -o server.exe

//TCP Server application
//======================
/*
#include “ZSocket.h”

int main()
{
WIN_SOCK_DECLARE
WIN_SOCK_INIT

ZSocket::ZServerSockTCP sockServer;
sockServer.Create();
sockServer.Bind(9999);
sockServer.Listen();

ZSocket::ZClientSockTCP sockClient;
sockServer.Accept(&sockClient);

char sBuff[250];

sockClient.Recv(sBuff, sizeof(sBuff));
printf(“\nReceived from client = [%s]\n”, sBuff);

strcpy(sBuff, “Lord of the ring is a good movie.”);
sockClient.Send(sBuff, sizeof(sBuff));

WIN_SOCK_SHUTDOWN
return 0;
}
*/

//UDP Server application
//======================

/*
#include “ZSocket.h”

int main()
{
WIN_SOCK_DECLARE
WIN_SOCK_INIT

ZSocket::ZServerSockUDP sockServer;
sockServer.Create();
sockServer.Bind(1234);

char sBuff[250];
sockaddr_in client;

sockServer.RecvFrom(sBuff, sizeof(sBuff), client);

printf(“\nReceived from client = %s\n”, sBuff);

strcpy(sBuff, “Dragula is a scary movie.”);

sockServer.SendTo(sBuff, sizeof(sBuff), client);

WIN_SOCK_SHUTDOWN
return 0;
}
*/

==========================================================================================

Sample code TCP & UDP client using ZSocket library

//Compiler version :: g++ (GCC) 4.6.0 20110428 (Red Hat 4.6.0-6)
//g++ client.cpp -o client.exe

//TCP Client application
//======================

/*
#include “ZSocket.h”

int main()
{
WIN_SOCK_DECLARE
WIN_SOCK_INIT

ZSocket::ZClientSockTCP sockClient;

sockClient.Create();

sockClient.Connect(“localhost”, 9999);

char sBuff[250] = “I like kajal agarwal. she is so cute.”;
sockClient.Send(sBuff, sizeof(sBuff));

sockClient.Recv(sBuff, sizeof(sBuff));
printf(“\nReceived from server = %s\n”, sBuff);

WIN_SOCK_SHUTDOWN
return 0;
}
*/

//UDP Client application
//======================
/*
#include “ZSocket.h”

int main()
{
WIN_SOCK_DECLARE
WIN_SOCK_INIT

ZSocket::ZClientSockUDP sockClient;

sockClient.Create();

sockClient.SetServerInfo(“localhost”, 1234);

char sBuff[250] = “Kajal agarwal is so cute and beautiful.”;
sockClient.Send(sBuff, sizeof(sBuff));

sockClient.Recv(sBuff, sizeof(sBuff));
printf(“\nReceived from server = %s\n”, sBuff);

WIN_SOCK_SHUTDOWN
return 0;
}
*/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: