Skip to content

AlexanderSilvaB/TcpUdpSocket

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TcpUdpSocket

C++ Class for UDP/TCP communications for Windows/Unix

This project is based on DatagramSocket from Glenn Butcher https://github.com/butcherg/DatagramSocket

Usage

#include "TcpUdpSocket.h"
#include "Thread.h"  //another project
#include <iostream>
#include <string>

using namespace std;

class MyThread: public Thread
{
    private:
        TcpUdpSocket *s;

    public:
	MyThread(TcpUdpSocket *sock)
	{
	    s = sock;
		Thread::CreateNewThread(this);
	}

	void Run(void*)
	{
	    char msg[4000];
		while (1) {
		    s->receive(msg, 4000);
		    cout << msg << endl;
		}
	}

};


int main(int argc, char *argv[])
{
    TcpUdpSocket *s = new TcpUdpSocket(5000, "255.255.255.255", TRUE, TRUE, TRUE);
	MyThread *t = new MyThread(s);

	string msg = "";

	while (1)  {
	    getline(cin, msg);
	    s->send(msg.c_str(), msg.length());
	}
	return 0;
}

The above example uses the Thread class from Glenn Butcher to implement a simple chat client. https://github.com/butcherg/Thread

In Windows you will need to add wsock32 to the linked libraries. Note that CMakeLists.txt is already doing that.

Releases

No releases published

Packages

No packages published

Languages

  • C++ 94.1%
  • CMake 5.9%