Delphi/FPC: Port Windows WinSock-based Socket classes to Mac


Port existing Windows Sockets-based Pascal language classes library to Mac OS (Delphi or Lazarus programming environment). Need support for both TCP and UDP protocols (SOCK_STREAM/SOCK_DGRAM), blocking and non-blocking sockets; don't using Indy. Non blocking sockets should not use separate thread per each socket.

Classes to port:

//private fields/methods are omitted

------------------- >8 ----------------------------



TIPSocketOnAccept = procedure (socket:TIPSocket);

TIPSocketOnConnecting = TIPSocketOnAccept;

TIPSocketOnRead = TIPSocketOnAccept;

TIPSocketOnConnect = TIPSocketOnAccept;

//base class for TCP/UDP sockets

TIPSocket = class


property Addr:sockaddr_in read GetAddr write FAddr;

property Host:string read GetHost write SetHost;

property Address:string read GetAddress write SetAddress;

property Port:integer read GetPort write SetPort;

property RemoteIP:string read GetRemoteIp;

property Error:cardinal read FError;

property Socket:TSocket read FSocket;

function NoAddr:boolean; // true if address/port is not set

constructor Create(const asynchronous:boolean = true);

destructor Destroy;override;

function EnableAsync:boolean;virtual; //enable non-blocking mode

function DisableAsync:boolean;virtual; //disable non-blocking mode

function Send(data:pointer; cb:cardinal):integer;virtual;abstract;

function Rece(data:pointer; cb:cardinal):integer;virtual;abstract;

procedure Close;

function BytesReceived:cardinal;

procedure SendReadSignal; // for non-blocking sockets sends FD_READ event to enforce reading data from the non-blocking socket.

class function GetRemoteComputerName(ip:ansistring):string; static;

class function ResolveHostName(s:ansistring):ansistring; static;

class function StrToAddr(s:ansistring):integer;static;

class function Select(nfds:Integer; readFDS, writeFDS, exceptFDS:PFDSet; timeout:PTimeVal):integer;


TTCPSocket = class(TIPSocket)



property OnRead:TIPSocketOnRead read FOnRead write FOnRead;

property OnClose:TIPSocketOnRead read FOnClose write FOnClose;

constructor Create(const asynchronous:boolean = true; const basesock:TSocket = -1);

function EnableAsync:boolean;override;

function Connect:boolean;virtual;

function Send(data:pointer; cb:cardinal):integer;override;

function Rece(data:pointer; cb:cardinal):integer;override;

function SendBlock(data:pointer; cb:cardinal; const asynctimeout:integer = -1):integer;virtual; //sends long blocks (more than IO buffer size)

function ReceBlock(data:pointer; cb:cardinal; const asynctimeout:integer = -1):integer;virtual; //receives long blocks (more than IO buffer size)


TTCPServerSocket = class(TTCPSocket)



property OnAccept:TIPSocketOnAccept read FOnAccept write FOnAccept;

property Error:cardinal read FError;

constructor Create(port:integer; const bindaddress:integer = INADDR_ANY; const asynchronous:boolean = true);

function Listen:integer;

function Accept:TTCPSocket;

function EnableAsync:boolean;override;


TUDPSocket = class(TIPSocket)



constructor Create(const asynchronous:boolean = true);

property OnRead:TIPSocketOnRead read FOnRead write FOnRead;

function Broadcast(enable:boolean):boolean; //enables UDP Broadcast

function MulticastTTL(value:integer):boolean;

function Multicast(address:ansistring):boolean; //enables multicast for the specified address, adds itself to Multicast group

function Send(data:pointer; cb:cardinal; _toaddr:integer; _toport:word):integer;

function Rece(data:pointer; cb:cardinal; fromaddr:pinteger; fromport:pword):integer;

function EnableAsync:boolean;override;


TUDPServerSocket = class(TUDPSocket)



constructor Create(port:integer; const bindaddress:integer = INADDR_ANY; const asynchronous:boolean = true);


Skills: Cocoa, Delphi, Mac OS, Socket IO

See more: delphi sendblock, fpc winsock, delphi create socket class, delphi winsock public, winsock fpc library, delphi winsock read, lazarus udp socket, winsock delphi, send data socket delphi mac, delphi fpc, delphi function winsock, delphi override socket library, windows socket programming, windows programming language, windows 8 programming, virtual function pointer, virtual destructor c, virtual destructor, virtual constructor, socket programming c#, programming Delphi, programming classes, pointer programming, pascal programming language, mac programming language

Project ID: #4466696

2 freelancers are bidding on average $630 for this job


Hello, why not use Indy? What delphi version you need ?

$735 USD in 10 days
(4 Reviews)

Please check my profile.

$525 USD in 3 days
(1 Review)