Networking

From EcereWiki
Jump to: navigation, search

Ecere Networking System

Socket Example

import "ecere"
MySocket socket { };
class MySocket : Socket
{
   void OnDisconnect(int code)
   {
   }
   uint OnReceive(const byte *buffer, uint count)
   {
   }
   void OnConnect()
   {
   }
}
void Test()
{
   socket.Connect("localhost", 1000);
}

Socket Example using Packet Class

import "ecere"
MySocket socket { };
class MyPacket : Packet
{
   int data;
};
class MySocket : Socket
{
   void OnReceivePacket(Packet packet)
   {
   }
}
void Test()
{
   socket.Connect("localhost", 1000);  
}

Service Example

import "ecere"

MyService service { port = 1000 };

class MyService : Service
{
   void OnAccept()
   {
      MySocket socket { this };
      socket.Send("Hello", 5);
   }
}

void Test()
{
   service.Start();
}

UDP Example

import "ecere"

MySocket socket { };

void Test()
{
   socket.DatagramHost(1000);
   socket.DatagramConnect("localhost", 1000");
   socket.Send("Hello", 5);
}