Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
laurentgom 2009-01-28 16:18:34 +00:00
commit 2f524481c1
974 changed files with 295448 additions and 0 deletions

View file

@ -0,0 +1,36 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.network.all;
public import
dsfml.network.ftp,
dsfml.network.http,
dsfml.network.ipaddress,
dsfml.network.packet,
dsfml.network.selector,
dsfml.network.socketstatus,
dsfml.network.sockettcp,
dsfml.network.socketudp;

View file

@ -0,0 +1,598 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.network.ftp;
import dsfml.system.common;
import dsfml.system.stringutil;
import dsfml.network.ipaddress;
/**
* Enumeration of transfer mode
*/
enum FtpTransferMode
{
BINARY, ///< Binary mode (file is transfered as a sequence of bytes)
ASCII, ///< Text mode using ASCII encoding
EBCDIC ///< Text mode using EBCDIC encoding
}
/**
* Enumerate all the valid status codes returned in
* a FTP response
*/
enum FtpStatus
{
// 1xx: the requested action is being initiated,
// expect another reply before proceeding with a new command
RESTARTMARKERREPLY = 110, ///< Restart marker reply
SERVICEREADYSOON = 120, ///< Service ready in N minutes
DATACONNECTIONALREADYOPENED = 125, ///< Data connection already opened, transfer starting
OPENINGDATACONNECTION = 150, ///< File status ok, about to open data connection
// 2xx: the requested action has been successfully completed
OK = 200, ///< Command ok
POINTLESSCOMMAND = 202, ///< Command not implemented
SYSTEMSTATUS = 211, ///< System status, or system help reply
DIRECTORYSTATUS = 212, ///< Directory status
FILESTATUS = 213, ///< File status
HELPMESSAGE = 214, ///< Help message
SYSTEMTYPE = 215, ///< NAME system type, where NAME is an official system name from the list in the Assigned Numbers document
SERVICEREADY = 220, ///< Service ready for new user
CLOSINGCONNECTION = 221, ///< Service closing control connection
DATACONNECTIONOPENED = 225, ///< Data connection open, no transfer in progress
CLOSINGDATACONNECTION = 226, ///< Closing data connection, requested file action successful
ENTERINGPASSIVEMODE = 227, ///< Entering passive mode
LOGGEDIN = 230, ///< User logged in, proceed. Logged out if appropriate
FILEACTIONOK = 250, ///< Requested file action ok
DIRECTORYOK = 257, ///< PATHNAME created
// 3xx: the command has been accepted, but the requested action
// is dormant, pending receipt of further information
NEEDPASSWORD = 331, ///< User name ok, need password
NEEDACCOUNTTOLOGIN = 332, ///< Need account for login
NEEDINFORMATION = 350, ///< Requested file action pending further information
// 4xx: the command was not accepted and the requested action did not take place,
// but the error condition is temporary and the action may be requested again
SERVICEUNAVAILABLE = 421, ///< Service not available, closing control connection
DATACONNECTIONUNAVAILABLE = 425, ///< Can't open data connection
TRANSFERABORTED = 426, ///< Connection closed, transfer aborted
FILEACTIONABORTED = 450, ///< Requested file action not taken
LOCALERROR = 451, ///< Requested action aborted, local error in processing
INSUFFICIENTSTORAGESPACE = 452, ///< Requested action not taken; insufficient storage space in system, file unavailable
// 5xx: the command was not accepted and
// the requested action did not take place
COMMANDUNKNOWN = 500, ///< Syntax error, command unrecognized
PARAMETERSUNKNOWN = 501, ///< Syntax error in parameters or arguments
COMMANDNOTIMPLEMENTED = 502, ///< Command not implemented
BADCOMMANDSEQUENCE = 503, ///< Bad sequence of commands
PARAMETERNOTIMPLEMENTED = 504, ///< Command not implemented for that parameter
NOTLOGGEDIN = 530, ///< Not logged in
NEEDACCOUNTTOSTORE = 532, ///< Need account for storing files
FILEUNAVAILABLE = 550, ///< Requested action not taken, file unavailable
PAGETYPEUNKNOWN = 551, ///< Requested action aborted, page type unknown
NOTENOUGHMEMORY = 552, ///< Requested file action aborted, exceeded storage allocation
FILENAMENOTALLOWED = 553, ///< Requested action not taken, file name not allowed
// 10xx: SFML custom codes
INVALIDRESPONSE = 1000, ///< Response is not a valid FTP one
CONNECTIONFAILED = 1001, ///< Connection with server failed
CONNECTIONCLOSED = 1002, ///< Connection with server closed
INVALIDFILE = 1003 ///< Invalid file to upload / download
}
/**
* This class provides methods for manipulating the FTP protocol (described in RFC 959).
* It provides easy access and transfers to remote directories and files on a FTP server.
*/
class Ftp : DSFMLObject
{
/**
* This class wraps a FTP response, which is basically :
* - a status code
* - a message
*/
static class FtpResponse : DSFMLObject
{
override void dispose()
{
sfFtpResponse_Destroy(m_ptr);
}
/**
* Convenience function to check if the response status code
* means a success
*
* Returns:
* True if status is success (code < 400)
*/
bool isOk()
{
return cast(bool)sfFtpResponse_IsOk(m_ptr);
}
/**
* Get the response status code
*
* Returns:
* Status code
*/
FtpStatus getStatus()
{
return sfFtpResponse_GetStatus(m_ptr);
}
/**
* Get the full message contained in the response
*
* Returns:
* The response message
*/
char[] getMessage()
{
return fromStringz(sfFtpResponse_GetMessage(m_ptr));
}
private:
this(void* ptr)
{
super(ptr);
}
// External ================================================================
extern (C)
{
typedef void function(void*) pf_sfFtpResponse_Destroy;
typedef int function(void*) pf_sfFtpResponse_IsOk;
typedef FtpStatus function(void*) pf_sfFtpResponse_GetStatus;
typedef char* function(void*) pf_sfFtpResponse_GetMessage;
static pf_sfFtpResponse_Destroy sfFtpResponse_Destroy;
static pf_sfFtpResponse_IsOk sfFtpResponse_IsOk;
static pf_sfFtpResponse_GetStatus sfFtpResponse_GetStatus;
static pf_sfFtpResponse_GetMessage sfFtpResponse_GetMessage;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfFtpResponse_Destroy = cast(pf_sfFtpResponse_Destroy)dll.getSymbol("sfFtpResponse_Destroy");
sfFtpResponse_IsOk = cast(pf_sfFtpResponse_IsOk)dll.getSymbol("sfFtpResponse_IsOk");
sfFtpResponse_GetStatus = cast(pf_sfFtpResponse_GetStatus)dll.getSymbol("sfFtpResponse_GetStatus");
sfFtpResponse_GetMessage = cast(pf_sfFtpResponse_GetMessage)dll.getSymbol("sfFtpResponse_GetMessage");
}
}
/**
* Specialization of FTP response returning a directory
*/
static class FtpDirectoryResponse : FtpResponse
{
override void dispose()
{
sfFtpDirectoryResponse_Destroy(m_ptr);
}
/**
* Get the directory returned in the response.
*
* Returns:
* Directory name
*/
char[] getDirectory()
{
return fromStringz(sfFtpDirectoryResponse_GetDirectory(m_ptr));
}
private:
this(void* ptr)
{
super(ptr);
}
// External ================================================================
extern (C)
{
typedef void function(void*) pf_sfFtpDirectoryResponse_Destroy;
typedef char* function(void*) pf_sfFtpDirectoryResponse_GetDirectory;
static pf_sfFtpDirectoryResponse_Destroy sfFtpDirectoryResponse_Destroy;
static pf_sfFtpDirectoryResponse_GetDirectory sfFtpDirectoryResponse_GetDirectory;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfFtpDirectoryResponse_Destroy = cast(pf_sfFtpDirectoryResponse_Destroy)dll.getSymbol("sfFtpDirectoryResponse_Destroy");
sfFtpDirectoryResponse_GetDirectory = cast(pf_sfFtpDirectoryResponse_GetDirectory)dll.getSymbol("sfFtpDirectoryResponse_GetDirectory");
}
}
/**
* Specialization of FTP response returning a filename listing.
*/
static class FtpListingResponse : FtpResponse
{
override void dispose()
{
sfFtpListingResponse_Destroy(m_ptr);
}
/**
* Get the number of files in the listing
*
* Returns:
* Total number of files
*/
size_t getCount()
{
return sfFtpListingResponse_GetCount(m_ptr);
}
/**
* Get the index-th filename in the directory
*
* Params:
* index = Index of the filename to get
*
* Returns:
* Filename
*/
char[] opIndex(size_t index)
{
return fromStringz(sfFtpListingResponse_GetFilename(m_ptr, index));
}
/**
* Foreach implementation
*/
int opApply(int delegate(char[]) dg)
{
size_t count = getCount();
int result;
for(int i = 0; i < count; i++)
{
result = dg(this[i]);
if (result)
break;
}
return result;
}
private:
this(void* ptr)
{
super(ptr);
}
// External ================================================================
extern (C)
{
typedef void function(void*) pf_sfFtpListingResponse_Destroy;
typedef size_t function(void*) pf_sfFtpListingResponse_GetCount;
typedef char* function(void*, size_t) pf_sfFtpListingResponse_GetFilename;
static pf_sfFtpListingResponse_Destroy sfFtpListingResponse_Destroy;
static pf_sfFtpListingResponse_GetCount sfFtpListingResponse_GetCount;
static pf_sfFtpListingResponse_GetFilename sfFtpListingResponse_GetFilename;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfFtpListingResponse_Destroy = cast(pf_sfFtpListingResponse_Destroy)dll.getSymbol("sfFtpListingResponse_Destroy");
sfFtpListingResponse_GetCount = cast(pf_sfFtpListingResponse_GetCount)dll.getSymbol("sfFtpListingResponse_GetCount");
sfFtpListingResponse_GetFilename = cast(pf_sfFtpListingResponse_GetFilename)dll.getSymbol("sfFtpListingResponse_GetFilename");
}
}
/**
* Default constructor
*/
this()
{
super(sfFtp_Create());
}
override void dispose()
{
sfFtp_Destroy(m_ptr);
}
/**
* Connect to the specified FTP server
*
* Params:
* server = FTP server to connect to
* port = Port used for connection (21 by default, standard FTP port)
* timeout = Maximum time to wait, in seconds (0 by default, means no timeout)
*
* Returns:
* Server response to the request
*/
FtpResponse connect(IPAddress server, ushort port = 21, float timeout = 0.f)
{
return new FtpResponse(sfFtp_Connect(m_ptr, server, port, timeout));
}
/**
* Log in using anonymous account
*
* Returns:
* Server response to the request
*/
FtpResponse login()
{
return new FtpResponse(sfFtp_LoginAnonymous(m_ptr));
}
/**
* Log in using a username and a password
*
* Params:
* username = User name
* password = password
*
* Returns:
* Server response to the request
*/
FtpResponse login(char[] username, char[] password)
{
return new FtpResponse(sfFtp_Login(m_ptr, toStringz(username), toStringz(password)));
}
/**
* Close the connection with FTP server
*
* Returns:
* Server response to the request
*/
FtpResponse disconnect()
{
return new FtpResponse(sfFtp_Disconnect(m_ptr));
}
/**
* Send a null command to prevent from being disconnected.
*
* Returns:
* Server response to the request
*/
FtpResponse keepAlive()
{
return new FtpResponse(sfFtp_KeepAlive(m_ptr));
}
/**
* Get the current working directory
*
* Returns:
* Server response to the request
*/
FtpDirectoryResponse getWorkingDirectory()
{
return new FtpDirectoryResponse(sfFtp_GetWorkingDirectory(m_ptr));
}
/**
* Get the content of the given directory (subdirectories and files).
*
* Params:
* directory = directory to list (null by default, the current one)
*
* Returns:
* Server response to the request
*/
FtpListingResponse getDirectoryListing(char[] directory = null)
{
return new FtpListingResponse(sfFtp_GetDirectoryListing(m_ptr, toStringz(directory)));
}
/**
* Change the current working directory
*
* Params:
* directory = New directory, relative to the current one.
*
* Returns:
* Server response to the request
*/
FtpResponse changeDirectory(char[] directory)
{
return new FtpResponse(sfFtp_ChangeDirectory(m_ptr, toStringz(directory)));
}
/**
* Go to the parent directory of the current one
*
* Returns:
* Server response to the request
*/
FtpResponse parentDirectory()
{
return new FtpResponse(sfFtp_ParentDirectory(m_ptr));
}
/**
* Create a new directory
*
* Params:
* name = name of the directory to create
*
* Returns:
* Server response to the request
*/
FtpResponse makeDirectory(char[] name)
{
return new FtpResponse(sfFtp_MakeDirectory(m_ptr, toStringz(name)));
}
/**
* remove an existing directory
*
* Params:
* name = name of the directory to remove
*
* Returns:
* Server response to the request
*/
FtpResponse deleteDirectory(char[] name)
{
return new FtpResponse(sfFtp_DeleteDirectory(m_ptr, toStringz(name)));
}
/**
* Rename a file
*
* Params:
* name = file to rename
* newName = new name
*
* Returns:
* Server response to the request
*/
FtpResponse renameFile(char[] name, char[] newName)
{
return new FtpResponse(sfFtp_RenameFile(m_ptr, toStringz(name), toStringz(newName)));
}
/**
* Remove an existing file
*
* Params:
* name = file to remove
*
* Returns:
* Server response to the request
*/
FtpResponse deleteFile(char[] name)
{
return new FtpResponse(sfFtp_DeleteFile(m_ptr, toStringz(name)));
}
/**
* Download a file from the server
*
* Params:
* distantFile = Path of the distant file to download
* destFile = Where to put the file on the local computer
* mode = transfer mode (binary by default)
*
* Returns:
* Server response to the request
*/
FtpResponse download(char[] distantFile, char[] destFile, FtpTransferMode mode = FtpTransferMode.BINARY)
{
return new FtpResponse(sfFtp_Download(m_ptr, toStringz(distantFile), toStringz(destFile), mode));
}
/**
* Upload a file to the server
*
* Params:
* localFile = Path of the local file to upload
* destPath = Where to put the file on the server
* mode = transfer mode (binary by default)
* Returns:
* Server response to the request
*/
FtpResponse upload(char[] localFile, char[] destFile, FtpTransferMode mode = FtpTransferMode.BINARY)
{
return new FtpResponse(sfFtp_Upload(m_ptr, toStringz(localFile), toStringz(destFile), mode));
}
private:
// External ====================================================================
extern (C)
{
typedef void* function() pf_sfFtp_Create;
typedef void function(void*) pf_sfFtp_Destroy;
typedef void* function(void*, IPAddress, ushort, float) pf_sfFtp_Connect;
typedef void* function(void*) pf_sfFtp_LoginAnonymous;
typedef void* function(void*, char*, char*) pf_sfFtp_Login;
typedef void* function(void*) pf_sfFtp_Disconnect;
typedef void* function(void*) pf_sfFtp_KeepAlive;
typedef void* function(void*) pf_sfFtp_GetWorkingDirectory;
typedef void* function(void*, char*) pf_sfFtp_GetDirectoryListing;
typedef void* function(void*, char*) pf_sfFtp_ChangeDirectory;
typedef void* function(void*) pf_sfFtp_ParentDirectory;
typedef void* function(void*, char*) pf_sfFtp_MakeDirectory;
typedef void* function(void*, char*) pf_sfFtp_DeleteDirectory;
typedef void* function(void*, char*, char*) pf_sfFtp_RenameFile;
typedef void* function(void*, char*) pf_sfFtp_DeleteFile;
typedef void* function(void*, char*, char*, FtpTransferMode) pf_sfFtp_Download;
typedef void* function(void*, char*, char*, FtpTransferMode) pf_sfFtp_Upload;
static pf_sfFtp_Create sfFtp_Create;
static pf_sfFtp_Destroy sfFtp_Destroy;
static pf_sfFtp_Connect sfFtp_Connect;
static pf_sfFtp_LoginAnonymous sfFtp_LoginAnonymous;
static pf_sfFtp_Login sfFtp_Login;
static pf_sfFtp_Disconnect sfFtp_Disconnect;
static pf_sfFtp_KeepAlive sfFtp_KeepAlive;
static pf_sfFtp_GetWorkingDirectory sfFtp_GetWorkingDirectory;
static pf_sfFtp_GetDirectoryListing sfFtp_GetDirectoryListing;
static pf_sfFtp_ChangeDirectory sfFtp_ChangeDirectory;
static pf_sfFtp_ParentDirectory sfFtp_ParentDirectory;
static pf_sfFtp_MakeDirectory sfFtp_MakeDirectory;
static pf_sfFtp_DeleteDirectory sfFtp_DeleteDirectory;
static pf_sfFtp_RenameFile sfFtp_RenameFile;
static pf_sfFtp_DeleteFile sfFtp_DeleteFile;
static pf_sfFtp_Download sfFtp_Download;
static pf_sfFtp_Upload sfFtp_Upload;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfFtp_Create = cast(pf_sfFtp_Create)dll.getSymbol("sfFtp_Create");
sfFtp_Destroy = cast(pf_sfFtp_Destroy)dll.getSymbol("sfFtp_Destroy");
sfFtp_Connect = cast(pf_sfFtp_Connect)dll.getSymbol("sfFtp_Connect");
sfFtp_LoginAnonymous = cast(pf_sfFtp_LoginAnonymous)dll.getSymbol("sfFtp_LoginAnonymous");
sfFtp_Login = cast(pf_sfFtp_Login)dll.getSymbol("sfFtp_Login");
sfFtp_Disconnect = cast(pf_sfFtp_Disconnect)dll.getSymbol("sfFtp_Disconnect");
sfFtp_KeepAlive = cast(pf_sfFtp_KeepAlive)dll.getSymbol("sfFtp_KeepAlive");
sfFtp_GetWorkingDirectory = cast(pf_sfFtp_GetWorkingDirectory)dll.getSymbol("sfFtp_GetWorkingDirectory");
sfFtp_GetDirectoryListing = cast(pf_sfFtp_GetDirectoryListing)dll.getSymbol("sfFtp_GetDirectoryListing");
sfFtp_ChangeDirectory = cast(pf_sfFtp_ChangeDirectory)dll.getSymbol("sfFtp_ChangeDirectory");
sfFtp_ParentDirectory = cast(pf_sfFtp_ParentDirectory)dll.getSymbol("sfFtp_ParentDirectory");
sfFtp_MakeDirectory = cast(pf_sfFtp_MakeDirectory)dll.getSymbol("sfFtp_MakeDirectory");
sfFtp_DeleteDirectory = cast(pf_sfFtp_DeleteDirectory)dll.getSymbol("sfFtp_DeleteDirectory");
sfFtp_RenameFile = cast(pf_sfFtp_RenameFile)dll.getSymbol("sfFtp_RenameFile");
sfFtp_DeleteFile = cast(pf_sfFtp_DeleteFile)dll.getSymbol("sfFtp_DeleteFile");
sfFtp_Download = cast(pf_sfFtp_Download)dll.getSymbol("sfFtp_Download");
sfFtp_Upload = cast(pf_sfFtp_Upload)dll.getSymbol("sfFtp_Upload");
}
}

View file

@ -0,0 +1,394 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.network.http;
import dsfml.system.stringutil;
import dsfml.system.common;
/**
* HTTP methods enumeration
*/
enum HttpMethod
{
GET, ///< Request in get mode, standard method to retrieve a page
POST, ///< Request in post mode, usually to send data to a page
HEAD ///< Request a page's header only
}
/**
* HTTP response status code
*/
enum HttpStatus
{
// 2xx: success
OK = 200, ///< Most common code returned when operation was successful
CREATED = 201, ///< The resource has successfully been created
ACCEPTED = 202, ///< The request has been accepted, but will be processed later by the server
NOCONTENT = 204, ///< Sent when the server didn't send any data in return
// 3xx: redirection
MULTIPLECHOICES = 300, ///< The requested page can be accessed from several locations
MOVEDPERMANENTLY = 301, ///< The requested page has permanently moved to a new location
MOVEDTEMPORARILY = 302, ///< The requested page has temporarily moved to a new location
NOTMODIFIED = 304, ///< For conditionnal requests, means the requested page hasn't changed and doesn't need to be refreshed
// 4xx: client error
BADREQUEST = 400, ///< The server couldn't understand the request (syntax error)
UNAUTHORIZED = 401, ///< The requested page needs an authentification to be accessed
FORBIDDEN = 403, ///< The requested page cannot be accessed at all, even with authentification
NOTFOUND = 404, ///< The requested page doesn't exist
// 5xx: server error
INTERNALSERVERERROR = 500, ///< The server encountered an unexpected error
NOTIMPLEMENTED = 501, ///< The server doesn't implement a requested feature
BADGATEWAY = 502, ///< The gateway server has received an error from the source server
SERVICENOTAVAILABLE = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...)
// 10xx: SFML custom codes
INVALIDRESPONSE = 1000, ///< Response is not a valid HTTP one
CONNECTIONFAILED = 1001 ///< Connection with server failed
}
/**
* This class provides methods for manipulating the HTTP protocol (described in
* RFC 1945).
* It can connect to a website, get files, send requests
*/
class Http : DSFMLObject
{
/**
* Wrapper for a http request, which is basically :
* - a header with a method, a target URI and a set of field/value pairs
* - an optional body (for POST requests)
*/
static class Response : DSFMLObject
{
override void dispose()
{
sfHttpResponse_Destroy(m_ptr);
}
/**
* Get the value of a field
*
* Params:
* field = Name of the field to get (case-insensitive)
* Returns:
* Value of the field, or enpty string if not found
*/
char[] getField(char[] field)
{
return fromStringz(sfHttpResponse_GetField(m_ptr, toStringz(field)));
}
/**
* Get the header status code
*
* Returns:
* header status code
*/
HttpStatus getStatus()
{
return sfHttpResponse_GetStatus(m_ptr);
}
/**
* Get the major HTTP version number of the response
*
* Returns:
* Major version number
*/
uint getMajorHTTPVersion()
{
return sfHttpResponse_GetMajorVersion(m_ptr);
}
/**
* Get the minor HTTP version number of the response
*
* Returns:
* Minor version number
*/
uint getMinorHTTPVersion()
{
return sfHttpResponse_GetMinorVersion(m_ptr);
}
/**
* Get the body of the response. The body can contain :
* - the requested page (for GET requests)
* - a response from the server (for POST requests)
* - nothing (for HEAD requests)
* - an error message (in case of an error)
*
* Returns:
* the response body
*/
char[] getBody()
{
return fromStringz(sfHttpResponse_GetBody(m_ptr));
}
private:
this(void* ptr)
{
super(ptr);
}
// External ================================================================
extern (C)
{
typedef void function(void*) pf_sfHttpResponse_Destroy;
typedef char* function(void*, char*) pf_sfHttpResponse_GetField;
typedef HttpStatus function(void*) pf_sfHttpResponse_GetStatus;
typedef uint function(void*) pf_sfHttpResponse_GetMajorVersion;
typedef uint function(void*) pf_sfHttpResponse_GetMinorVersion;
typedef char* function(void*) pf_sfHttpResponse_GetBody;
static pf_sfHttpResponse_Destroy sfHttpResponse_Destroy;
static pf_sfHttpResponse_GetField sfHttpResponse_GetField;
static pf_sfHttpResponse_GetStatus sfHttpResponse_GetStatus;
static pf_sfHttpResponse_GetMajorVersion sfHttpResponse_GetMajorVersion;
static pf_sfHttpResponse_GetMinorVersion sfHttpResponse_GetMinorVersion;
static pf_sfHttpResponse_GetBody sfHttpResponse_GetBody;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfHttpResponse_Destroy = cast(pf_sfHttpResponse_Destroy)dll.getSymbol("sfHttpResponse_Destroy");
sfHttpResponse_GetField = cast(pf_sfHttpResponse_GetField)dll.getSymbol("sfHttpResponse_GetField");
sfHttpResponse_GetStatus = cast(pf_sfHttpResponse_GetStatus)dll.getSymbol("sfHttpResponse_GetStatus");
sfHttpResponse_GetMajorVersion = cast(pf_sfHttpResponse_GetMajorVersion)dll.getSymbol("sfHttpResponse_GetMajorVersion");
sfHttpResponse_GetMinorVersion = cast(pf_sfHttpResponse_GetMinorVersion)dll.getSymbol("sfHttpResponse_GetMinorVersion");
sfHttpResponse_GetBody = cast(pf_sfHttpResponse_GetBody)dll.getSymbol("sfHttpResponse_GetBody");
}
}
/**
* Wrapper for a HTTP response which is basically :
* - a header with a status code and a set of field/value pairs
* - a body (the content of the requested resource)
*/
static class Request : DSFMLObject
{
/**
* Constructor
*
* Params:
* requestMethod = Method to use for the request (Get by default)
* uri = Target URI ("/" by default -- index page)
* requestBody = Content of the request's body (empty by default)
*/
this(HttpMethod requestMethod = HttpMethod.GET, char[] uri = "/", char[] requestBody = "")
{
super(sfHttpRequest_Create());
sfHttpRequest_SetMethod(m_ptr, requestMethod);
sfHttpRequest_SetURI(m_ptr, toStringz(uri));
sfHttpRequest_SetBody(m_ptr, toStringz(requestBody));
}
/**
* Set the value of a field. Field is created if it doesn't exists.
*
* Params:
* field = name of the field to set (case-insensitive)
* value = value of the field
*/
void setField(char[] field, char[] value)
{
sfHttpRequest_SetField(m_ptr, toStringz(field), toStringz(value));
}
/**
* Set the request method.
*
* Params:
* requestMethod = Method to use for the request.
*/
void setMethod(HttpMethod requestMethod)
{
sfHttpRequest_SetMethod(m_ptr, requestMethod);
}
/**
* Set the target URI of the request.
*
* Params:
* uri = URI to request, local to the host.
* Returns:
*/
void setURI(char[] uri)
{
sfHttpRequest_SetURI(m_ptr, toStringz(uri));
}
/**
* Set the HTTP version of the request.
*
* Params:
* major = Major version number
* minor = Minor version number
*/
void setHttpVersion(uint major, uint minor)
{
sfHttpRequest_SetHttpVersion(m_ptr, major, minor);
}
/**
* Set the body of the request. This parameter is optionnal and make sense
* only for POST requests.
*
* Params:
* requestBody = Content of the request body.
*/
void setBody(char[] requestBody)
{
sfHttpRequest_SetBody(m_ptr, toStringz(requestBody));
}
private:
// External ================================================================
extern (C)
{
typedef void* function() pf_sfHttpRequest_Create;
typedef void function(void*) pf_sfHttpRequest_Destroy;
typedef void function(void*, char*, char*) pf_sfHttpRequest_SetField;
typedef void function(void*, HttpMethod) pf_sfHttpRequest_SetMethod;
typedef void function(void*, char*) pf_sfHttpRequest_SetURI;
typedef void function(void*, uint, uint) pf_sfHttpRequest_SetHttpVersion;
typedef void function(void*, char*) pf_sfHttpRequest_SetBody;
static pf_sfHttpRequest_Create sfHttpRequest_Create;
static pf_sfHttpRequest_Destroy sfHttpRequest_Destroy;
static pf_sfHttpRequest_SetField sfHttpRequest_SetField;
static pf_sfHttpRequest_SetMethod sfHttpRequest_SetMethod;
static pf_sfHttpRequest_SetURI sfHttpRequest_SetURI;
static pf_sfHttpRequest_SetHttpVersion sfHttpRequest_SetHttpVersion;
static pf_sfHttpRequest_SetBody sfHttpRequest_SetBody;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfHttpRequest_Create = cast(pf_sfHttpRequest_Create)dll.getSymbol("sfHttpRequest_Create");
sfHttpRequest_Destroy = cast(pf_sfHttpRequest_Destroy)dll.getSymbol("sfHttpRequest_Destroy");
sfHttpRequest_SetField = cast(pf_sfHttpRequest_SetField)dll.getSymbol("sfHttpRequest_SetField");
sfHttpRequest_SetMethod = cast(pf_sfHttpRequest_SetMethod)dll.getSymbol("sfHttpRequest_SetMethod");
sfHttpRequest_SetURI = cast(pf_sfHttpRequest_SetURI)dll.getSymbol("sfHttpRequest_SetURI");
sfHttpRequest_SetHttpVersion = cast(pf_sfHttpRequest_SetHttpVersion)dll.getSymbol("sfHttpRequest_SetHttpVersion");
sfHttpRequest_SetBody = cast(pf_sfHttpRequest_SetBody)dll.getSymbol("sfHttpRequest_SetBody");
}
}
/**
* Constructor
*/
this()
{
super(sfHttp_Create());
}
/**
* Constructor
*
* Params:
* host = Web server to connect to
* port = port to use for connection (0 by default -- use the standard port of the protocol)
*/
this(char[] host, ushort port = 0)
{
super(sfHttp_Create());
sfHttp_SetHost(m_ptr, toStringz(host), port);
}
override void dispose()
{
sfHttp_Destroy(m_ptr);
}
/**
* Set the target host.
*
* Params:
* host = Web server to connect to
* port = port to use for connection (0 by default -- use the standard port of the protocol)
*/
void setHost(char[] host, ushort port = 0)
{
sfHttp_SetHost(m_ptr, toStringz(host), port);
}
/**
* Send a HTTP request and return the server's response.
* You must be connected to a host before sending requests.
* Any missing mandatory header field will be added with an appropriate value.
*
* Warning : this function waits for the server's response and may
* not return instantly; use a thread if you don't want to block your
* application.
*
* Params:
* req = Request to send
*
* Returns:
* Server's response
*/
Response sendRequest(Request req)
{
return new Response( sfHttp_SendRequest(m_ptr, req.getNativePointer) );
}
private:
// External ====================================================================
extern (C)
{
typedef void* function() pf_sfHttp_Create;
typedef void function(void*) pf_sfHttp_Destroy;
typedef void function(void*, char*, ushort) pf_sfHttp_SetHost;
typedef void* function(void*, void*) pf_sfHttp_SendRequest;
static pf_sfHttp_Create sfHttp_Create;
static pf_sfHttp_Destroy sfHttp_Destroy;
static pf_sfHttp_SetHost sfHttp_SetHost;
static pf_sfHttp_SendRequest sfHttp_SendRequest;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfHttp_Create = cast(pf_sfHttp_Create)dll.getSymbol("sfHttp_Create");
sfHttp_Destroy = cast(pf_sfHttp_Destroy)dll.getSymbol("sfHttp_Destroy");
sfHttp_SetHost = cast(pf_sfHttp_SetHost)dll.getSymbol("sfHttp_SetHost");
sfHttp_SendRequest = cast(pf_sfHttp_SendRequest)dll.getSymbol("sfHttp_SendRequest");
}
}

View file

@ -0,0 +1,164 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.network.ipaddress;
import dsfml.system.common;
import dsfml.system.stringutil;
/**
* IPAddress provides easy manipulation of IP v4 addresses
*/
struct IPAddress
{
/**
* Construct the address from a string
*
* Params:
* address = IP address ("xxx.xxx.xxx.xxx") or network name
*
*/
static IPAddress opCall(char[] address)
{
return sfIPAddress_FromString(toStringz(address));
}
/**
* Construct the address from 4 bytes
*
* Params:
* byte0 = First byte of the address
* byte1 = Second byte of the address
* byte2 = Third byte of the address
* byte3 = Fourth byte of the address
*
*/
static IPAddress opCall(ubyte byte0, ubyte byte1, ubyte byte2, ubyte byte3)
{
return sfIPAddress_FromBytes(byte0, byte1, byte2, byte3);
}
/**
* Construct the address from a 32 bits integer
*
* Params:
* address = 4 bytes of the address packed into a 32 bits integer
*
*/
static IPAddress opCall(uint address)
{
return sfIPAddress_FromInteger(address);
}
/**
* Tell if the address is a valid one
*
* Returns:
* True if address has a valid syntax
*
*/
bool isValid()
{
return cast(bool)sfIPAddress_IsValid(*this);
}
/**
* Get the computer's local IP address (from the LAN point of view)
*
* Returns:
* Local IP address
*
*/
static IPAddress getLocalAddress()
{
return sfIPAddress_GetLocalAddress();
}
/**
* Get the computer's public IP address (from the web point of view).
* The only way to get a public address is to ask it to a
* distant website ; as a consequence, this function may be
* very slow -- use it as few as possible !
*
* Returns:
* Public IP address
*
*/
static IPAddress getPublicAddress()
{
return sfIPAddress_GetPublicAddress();
}
bool opEqual(IPAddress other)
{
return Address == other.Address;
}
/**
* Local host address (to connect to the same computer).
*/
static IPAddress LOCALHOST()
{
return sfIPAddress_LocalHost();
}
byte[16] Address;
}
private:
extern (C)
{
typedef IPAddress function(char*) pf_sfIPAddress_FromString;
typedef IPAddress function(ubyte, ubyte, ubyte, ubyte) pf_sfIPAddress_FromBytes;
typedef IPAddress function(uint) pf_sfIPAddress_FromInteger;
typedef int function(IPAddress) pf_sfIPAddress_IsValid;
typedef IPAddress function() pf_sfIPAddress_GetLocalAddress;
typedef IPAddress function() pf_sfIPAddress_GetPublicAddress;
typedef IPAddress function() pf_sfIPAddress_LocalHost;
static pf_sfIPAddress_FromString sfIPAddress_FromString;
static pf_sfIPAddress_FromBytes sfIPAddress_FromBytes;
static pf_sfIPAddress_FromInteger sfIPAddress_FromInteger;
static pf_sfIPAddress_IsValid sfIPAddress_IsValid;
static pf_sfIPAddress_GetLocalAddress sfIPAddress_GetLocalAddress;
static pf_sfIPAddress_GetPublicAddress sfIPAddress_GetPublicAddress;
static pf_sfIPAddress_LocalHost sfIPAddress_LocalHost;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfIPAddress_FromBytes = cast(pf_sfIPAddress_FromBytes)dll.getSymbol("sfIPAddress_FromBytes");
sfIPAddress_FromString = cast(pf_sfIPAddress_FromString)dll.getSymbol("sfIPAddress_FromString");
sfIPAddress_FromInteger = cast(pf_sfIPAddress_FromInteger)dll.getSymbol("sfIPAddress_FromInteger");
sfIPAddress_GetLocalAddress = cast(pf_sfIPAddress_GetLocalAddress)dll.getSymbol("sfIPAddress_GetLocalAddress");
sfIPAddress_GetPublicAddress = cast(pf_sfIPAddress_GetPublicAddress)dll.getSymbol("sfIPAddress_GetPublicAddress");
sfIPAddress_IsValid = cast(pf_sfIPAddress_IsValid)dll.getSymbol("sfIPAddress_IsValid");
sfIPAddress_LocalHost = cast(pf_sfIPAddress_LocalHost)dll.getSymbol("sfIPAddress_LocalHost");
}

View file

@ -0,0 +1,413 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.network.packet;
import dsfml.system.common;
import dsfml.system.stringutil;
/**
* Packet wraps data to send / to receive through the network
*
* The order of insertion and extraction must be the same.
*
* You can derive from Packet and override onSend and onReceive to do custom operations before send or after reception.
*
* Litterals integer are promoted to int.
* Litterals floating point are promoted to float.
*
* Extraction or insertion can be specified with explicit template.
* Examples:
* ------------------------------------------------------------
* Packet p = new Packet();
*
* int i = 32, j = 42;
* char[] k = hello;
*
* p.set(i, k, j); //Set the data in the packet
*
* int a, b;
* char[] c;
* p.get(a, c, b); //Get data from the packet
*
* //...
*
* Packet p = new Packet();
* p.set!(byte)(5); // Litteral are inserted with byte type
* ------------------------------------------------------------
*
* See_Also:
* $(LINK2 http://www.digitalmars.com/d/1.0/lex.html, D litterals Specification) for more informations.
*/
class Packet : DSFMLObject
{
/**
* Default constructor
*
*/
this()
{
super(sfPacket_Create());
}
override void dispose()
{
sfPacket_Destroy(m_ptr);
}
/**
* Append data to the end of the packet.
*
* Params:
* data = Array of data to append
*
*/
void append(byte[] data)
{
if (data !is null)
sfPacket_Append(m_ptr, data.ptr, data.length);
}
/**
* Clear the packet data
*
*/
void clear()
{
sfPacket_Clear(m_ptr);
}
/**
* Get an array to the data contained in the packet
* $(B the returned array may be invalid after you
* append data to the packet)
*
* Returns:
* array of data
*
* Remarks:
* return an array of $(B all) data in the packet.
*
* ----------
* Packet p = new Packet();
*
* char[] str1 = "Hi";
* char[] str2 = "Hello";
*
* p.set(str1, str2);
*
* // Retrieve str1 from packet
* char[] str3;
* p.get(str3);
*
* // Returns an array containing str1 and str2.
* byte[] ptr = p.getData();
* ----------
*/
byte[] getData()
{
if (canRead)
return sfPacket_GetData(m_ptr)[0..getDataSize];
}
/**
* Get the size of the data contained in the packet
*
* Returns:
* Data size, in bytes
*/
uint getDataSize()
{
return sfPacket_GetDataSize(m_ptr);
}
/**
* Tell if the reading position has reached the end of the packet
*
* Returns:
* true if all data have been read.
*/
bool endOfPacket()
{
return cast(bool)sfPacket_EndOfPacket(m_ptr);
}
/**
* Tell if the packet is valid for reading
*
* Returns:
* True if data can be extracted from the packet
*
*/
bool canRead()
{
return cast(bool)sfPacket_CanRead(m_ptr);
}
/**
* Add new variables to the packet
* Accept (u)byte, (u)short, (u)int, float, double, char[] and wchar[] types
*/
Packet set(T...)(T t)
{
foreach (v; t)
internalSet(t);
return this;
}
/**
* Retrieve data from the packet
* Accept (u)byte, (u)short, (u)int, float, double, char[] and wchar[] types
*/
Packet get(T...)(ref T t)
{
foreach (v; t)
internalGet(t);
return this;
}
/**
* Called before packet is send
*
* Params:
* size = Variable to fill with the size of the data to send
* Returns:
* Array of byte to send
*/
byte[] onSend()
{
return getData();
}
/**
* Called after a packet has been received
*
* Params:
* data = Array of byte received
*/
void onReceive(byte[] data)
{
append(data);
}
private:
void internalGet(ref bool data)
{
data = cast(bool)sfPacket_ReadInt32(m_ptr);
}
void internalGet(ref byte data)
{
data = sfPacket_ReadInt8(m_ptr);
}
void internalGet(ref ubyte data)
{
data = sfPacket_ReadUint8(m_ptr);
}
void internalGet(ref short data)
{
data = sfPacket_ReadInt16(m_ptr);
}
void internalGet(ref ushort data)
{
data = sfPacket_ReadUint16(m_ptr);
}
void internalGet(ref int data)
{
data = sfPacket_ReadInt32(m_ptr);
}
void internalGet(ref uint data)
{
data = sfPacket_ReadUint32(m_ptr);
}
void internalGet(ref float data)
{
data = sfPacket_ReadFloat(m_ptr);
}
void internalGet(ref double data)
{
data = sfPacket_ReadDouble(m_ptr);
}
void internalGet(ref char[] data)
{
scope char[] temp = new char[sfPacket_GetDataSize(m_ptr)];
sfPacket_ReadString(m_ptr, temp.ptr);
size_t l = fromStringz(temp.ptr).length;
data = new char[l];
data[] = temp[0 .. l];
}
void internalGet(ref wchar[] data)
{
scope wchar[] temp = new wchar[sfPacket_GetDataSize(m_ptr)];
sfPacket_ReadWideString(m_ptr, temp.ptr);
size_t l = fromStringz(temp.ptr).length;
data = new wchar[l];
data[] = temp[0 .. l];
}
void internalSet(bool data)
{
sfPacket_WriteInt32(m_ptr, cast(int)data);
}
void internalSet(byte data)
{
sfPacket_WriteInt8(m_ptr, data);
}
void internalSet(ubyte data)
{
sfPacket_WriteUint8(m_ptr, data);
}
void internalSet(short data)
{
sfPacket_WriteInt16(m_ptr, data);
}
void internalSet(ushort data)
{
sfPacket_WriteUint16(m_ptr, data);
}
void internalSet(int data)
{
sfPacket_WriteInt32(m_ptr, data);
}
void internalSet(uint data)
{
sfPacket_WriteUint32(m_ptr, data);
}
void internalSet(float data)
{
sfPacket_WriteFloat(m_ptr, data);
}
void internalSet(double data)
{
sfPacket_WriteDouble(m_ptr, data);
}
void internalSet(char[] data)
{
sfPacket_WriteString(m_ptr, toStringz(data));
}
void internalSet(wchar[] data)
{
sfPacket_WriteWideString(m_ptr, toStringz(data));
}
// External ====================================================================
extern (C)
{
typedef void* function() pf_sfPacket_Create;
typedef void function(void*) pf_sfPacket_Destroy;
typedef void function(void*, void*, size_t) pf_sfPacket_Append;
typedef void function(void*) pf_sfPacket_Clear;
typedef byte* function(void*) pf_sfPacket_GetData;
typedef uint function(void*) pf_sfPacket_GetDataSize;
typedef int function(void*) pf_sfPacket_EndOfPacket;
typedef int function(void*) pf_sfPacket_CanRead;
typedef byte function(void*) pf_sfPacket_ReadInt8;
typedef ubyte function(void*) pf_sfPacket_ReadUint8;
typedef short function(void*) pf_sfPacket_ReadInt16;
typedef ushort function(void*) pf_sfPacket_ReadUint16;
typedef int function(void*) pf_sfPacket_ReadInt32;
typedef uint function(void*) pf_sfPacket_ReadUint32;
typedef float function(void*) pf_sfPacket_ReadFloat;
typedef double function(void*) pf_sfPacket_ReadDouble;
typedef void function(void*, char*) pf_sfPacket_ReadString;
typedef void function(void*, wchar*) pf_sfPacket_ReadWideString;
typedef void function(void*, byte) pf_sfPacket_WriteInt8;
typedef void function(void*, ubyte) pf_sfPacket_WriteUint8;
typedef void function(void*, short) pf_sfPacket_WriteInt16;
typedef void function(void*, ushort) pf_sfPacket_WriteUint16;
typedef void function(void*, int) pf_sfPacket_WriteInt32;
typedef void function(void*, uint) pf_sfPacket_WriteUint32;
typedef void function(void*, float) pf_sfPacket_WriteFloat;
typedef void function(void*, double) pf_sfPacket_WriteDouble;
typedef void function(void*, char*) pf_sfPacket_WriteString;
typedef void function(void*, wchar*) pf_sfPacket_WriteWideString;
static pf_sfPacket_Create sfPacket_Create;
static pf_sfPacket_Destroy sfPacket_Destroy;
static pf_sfPacket_Append sfPacket_Append;
static pf_sfPacket_Clear sfPacket_Clear;
static pf_sfPacket_GetData sfPacket_GetData;
static pf_sfPacket_GetDataSize sfPacket_GetDataSize;
static pf_sfPacket_EndOfPacket sfPacket_EndOfPacket;
static pf_sfPacket_CanRead sfPacket_CanRead;
static pf_sfPacket_ReadInt8 sfPacket_ReadInt8;
static pf_sfPacket_ReadUint8 sfPacket_ReadUint8;
static pf_sfPacket_ReadInt16 sfPacket_ReadInt16;
static pf_sfPacket_ReadUint16 sfPacket_ReadUint16;
static pf_sfPacket_ReadInt32 sfPacket_ReadInt32;
static pf_sfPacket_ReadUint32 sfPacket_ReadUint32;
static pf_sfPacket_ReadFloat sfPacket_ReadFloat;
static pf_sfPacket_ReadDouble sfPacket_ReadDouble;
static pf_sfPacket_ReadString sfPacket_ReadString;
static pf_sfPacket_ReadWideString sfPacket_ReadWideString;
static pf_sfPacket_WriteInt8 sfPacket_WriteInt8;
static pf_sfPacket_WriteUint8 sfPacket_WriteUint8;
static pf_sfPacket_WriteInt16 sfPacket_WriteInt16;
static pf_sfPacket_WriteUint16 sfPacket_WriteUint16;
static pf_sfPacket_WriteInt32 sfPacket_WriteInt32;
static pf_sfPacket_WriteUint32 sfPacket_WriteUint32;
static pf_sfPacket_WriteFloat sfPacket_WriteFloat;
static pf_sfPacket_WriteDouble sfPacket_WriteDouble;
static pf_sfPacket_WriteString sfPacket_WriteString;
static pf_sfPacket_WriteWideString sfPacket_WriteWideString;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfPacket_Append = cast(pf_sfPacket_Append)dll.getSymbol("sfPacket_Append");
sfPacket_CanRead = cast(pf_sfPacket_CanRead)dll.getSymbol("sfPacket_CanRead");
sfPacket_Clear = cast(pf_sfPacket_Clear)dll.getSymbol("sfPacket_Clear");
sfPacket_Create = cast(pf_sfPacket_Create)dll.getSymbol("sfPacket_Create");
sfPacket_Destroy = cast(pf_sfPacket_Destroy)dll.getSymbol("sfPacket_Destroy");
sfPacket_EndOfPacket = cast(pf_sfPacket_EndOfPacket)dll.getSymbol("sfPacket_EndOfPacket");
sfPacket_GetData = cast(pf_sfPacket_GetData)dll.getSymbol("sfPacket_GetData");
sfPacket_GetDataSize = cast(pf_sfPacket_GetDataSize)dll.getSymbol("sfPacket_GetDataSize");
sfPacket_ReadDouble = cast(pf_sfPacket_ReadDouble)dll.getSymbol("sfPacket_ReadDouble");
sfPacket_ReadFloat = cast(pf_sfPacket_ReadFloat)dll.getSymbol("sfPacket_ReadFloat");
sfPacket_ReadInt16 = cast(pf_sfPacket_ReadInt16)dll.getSymbol("sfPacket_ReadInt16");
sfPacket_ReadInt32 = cast(pf_sfPacket_ReadInt32)dll.getSymbol("sfPacket_ReadInt32");
sfPacket_ReadInt8 = cast(pf_sfPacket_ReadInt8)dll.getSymbol("sfPacket_ReadInt8");
sfPacket_ReadString = cast(pf_sfPacket_ReadString)dll.getSymbol("sfPacket_ReadString");
sfPacket_ReadWideString = cast(pf_sfPacket_ReadWideString)dll.getSymbol("sfPacket_ReadWideString");
sfPacket_ReadUint16 = cast(pf_sfPacket_ReadUint16)dll.getSymbol("sfPacket_ReadUint16");
sfPacket_ReadUint32 = cast(pf_sfPacket_ReadUint32)dll.getSymbol("sfPacket_ReadUint32");
sfPacket_ReadUint8 = cast(pf_sfPacket_ReadUint8)dll.getSymbol("sfPacket_ReadUint8");
sfPacket_WriteDouble = cast(pf_sfPacket_WriteDouble)dll.getSymbol("sfPacket_WriteDouble");
sfPacket_WriteFloat = cast(pf_sfPacket_WriteFloat)dll.getSymbol("sfPacket_WriteFloat");
sfPacket_WriteInt16 = cast(pf_sfPacket_WriteInt16)dll.getSymbol("sfPacket_WriteInt16");
sfPacket_WriteInt32 = cast(pf_sfPacket_WriteInt32)dll.getSymbol("sfPacket_WriteInt32");
sfPacket_WriteInt8 = cast(pf_sfPacket_WriteInt8)dll.getSymbol("sfPacket_WriteInt8");
sfPacket_WriteString = cast(pf_sfPacket_WriteString)dll.getSymbol("sfPacket_WriteString");
sfPacket_WriteWideString = cast(pf_sfPacket_WriteWideString)dll.getSymbol("sfPacket_WriteWideString");
sfPacket_WriteUint16 = cast(pf_sfPacket_WriteUint16)dll.getSymbol("sfPacket_WriteUint16");
sfPacket_WriteUint32 = cast(pf_sfPacket_WriteUint32)dll.getSymbol("sfPacket_WriteUint32");
sfPacket_WriteUint8 = cast(pf_sfPacket_WriteUint8)dll.getSymbol("sfPacket_WriteUint8");
}
}

View file

@ -0,0 +1,187 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.network.selector;
import dsfml.network.sockettcp;
import dsfml.network.socketudp;
import dsfml.system.common;
/**
* Selector TCP allow reading from multiple sockets
* without blocking. It's a kind of multiplexer. Use SocketTCP or
* SocketUDP aliases.
*/
class Selector(T) : DSFMLObject
{
//Ensure type is correct
static if (!is(T : SocketTCP) && !is(T : SocketUDP))
static assert("Only SocketTCP and SocketUDP are valid for Selector.");
/**
* Default constructor
*/
this()
{
super(sfSelector_Create());
}
override void dispose()
{
sfSelector_Destroy(m_ptr);
}
/**
* Add a socket to watch
*
* Params:
* socket = A tcp or udp socket
*/
void add(T socket)
{
if (!(socket.getNativePointer in m_watchedSockets))
{
sfSelector_Add(m_ptr, socket.getNativePointer);
m_watchedSockets[socket.getNativePointer] = socket;
m_numSocketsWatched++;
}
}
/**
* Remove a previously added socket
*
* Params:
* socket = A tcp or udp socket
*/
void remove(T socket)
{
if (socket.getNativePointer in m_watchedSockets)
{
sfSelector_Remove(m_ptr, socket.getNativePointer);
m_watchedSockets.remove(socket.getNativePointer);
m_numSocketsWatched--;
}
}
/**
* Clear all sockets being watched
*/
void clear()
{
sfSelector_Clear(m_ptr);
foreach(key; m_watchedSockets.keys)
m_watchedSockets.remove(key);
m_numSocketsWatched = 0;
}
/**
* Wait and collect sockets which are ready for reading.
* This functions will return either when at least one socket
* is ready, or when the given time is out
*
* Params:
* timeout = Maximum time to wait, in seconds (0 to disable timeout)
*
* Returns:
* Number of sockets ready
*/
uint wait(float timeout = 0.f)
{
return sfSelector_Wait(m_ptr, timeout);
}
/**
* After a call to Wait(), get the Index-th socket which is
* ready for reading. The total number of sockets ready
* is the integer returned by the previous call to Wait()
*
* Params:
* index = Index of the socket to get
*
* Returns:
* The Index-th socket
*/
T GetSocketsReady(uint index)
{
return m_watchedSockets[sfSelector_GetSocketReady(m_ptr, index)];
}
private:
size_t m_numSocketsWatched;
T[void*] m_watchedSockets;
// External ====================================================================
extern (C)
{
typedef void* function() pf_sfSelector_Create;
typedef void function(void*) pf_sfSelector_Destroy;
typedef void function(void*, void*) pf_sfSelector_Add;
typedef void function(void*, void*) pf_sfSelector_Remove;
typedef void function(void*) pf_sfSelector_Clear;
typedef uint function(void*, float) pf_sfSelector_Wait;
typedef void* function(void*, uint) pf_sfSelector_GetSocketReady;
static pf_sfSelector_Create sfSelector_Create;
static pf_sfSelector_Destroy sfSelector_Destroy;
static pf_sfSelector_Add sfSelector_Add;
static pf_sfSelector_Remove sfSelector_Remove;
static pf_sfSelector_Clear sfSelector_Clear;
static pf_sfSelector_Wait sfSelector_Wait;
static pf_sfSelector_GetSocketReady sfSelector_GetSocketReady;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
static if (is (T : SocketTCP))
{
char[] symbol = "sfSelectorTCP";
}
else static if (is (T : SocketUDP))
{
char[] symbol = "sfSelectorUDP";
}
sfSelector_Add = cast(pf_sfSelector_Add)dll.getSymbol(symbol ~ "_Add");
sfSelector_Clear = cast(pf_sfSelector_Clear)dll.getSymbol(symbol ~ "_Clear");
sfSelector_Create = cast(pf_sfSelector_Create)dll.getSymbol(symbol ~ "_Create");
sfSelector_Destroy = cast(pf_sfSelector_Destroy)dll.getSymbol(symbol ~ "_Destroy");
sfSelector_GetSocketReady = cast(pf_sfSelector_GetSocketReady)dll.getSymbol(symbol ~ "_GetSocketReady");
sfSelector_Wait = cast(pf_sfSelector_Wait)dll.getSymbol(symbol ~ "_Wait");
sfSelector_Remove = cast(pf_sfSelector_Remove)dll.getSymbol(symbol ~ "_Remove");
}
}
/**
* alias of selector for TCP or UDP Socket.
*/
alias Selector!(SocketTCP) SelectorTCP;
/// ditto
alias Selector!(SocketUDP) SelectorUDP;

View file

@ -0,0 +1,37 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.network.socketstatus;
/**
* Enumeration of status returned by socket functions
*/
enum SocketStatus
{
DONE, ///
NOTREADY, ///
DISCONNECTED, ///
UNEXPECTEDERROR ///
}

View file

@ -0,0 +1,268 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.network.sockettcp;
import dsfml.network.ipaddress;
import dsfml.network.packet;
import dsfml.network.socketstatus;
import dsfml.system.common;
/**
* SocketTCP wraps a socket using TCP protocol to send data safely (but a bit slower)
*/
class SocketTCP : DSFMLObject
{
/**
* Default constructor
*/
this()
{
super(sfSocketTCP_Create());
m_intermediatePacket = new Packet();
}
override void dispose()
{
sfSocketTCP_Destroy(m_ptr);
}
/**
* Connect to another computer on a specified port
*
* Params:
* port = Port to use for transfers (warning : ports < 1024 are reserved)
* hostAddress = IP Address of the host to connect to
* timeout = Maximum time to wait in seconds (0 by default : no timeout)
*
* Returns:
* True if operation has been successful
*/
bool connect(ushort port, IPAddress hostAddress, float timeout = 0.f)
{
return cast(bool) !sfSocketTCP_Connect(m_ptr, port, hostAddress, timeout);
}
/**
* Listen to a specified port for incoming data or connections
*
* Params:
* port = Port to listen to
*
* Returns:
* True if operation has been successful
*/
bool listen(ushort port)
{
return cast(bool)sfSocketTCP_Listen(m_ptr, port);
}
/**
* Wait for a connection (must be listening to a port).
* This function is blocking.
*
* Params:
* connected = Socket containing the connection with the connected client
*
* Returns:
* Status code
*/
SocketStatus accept(SocketTCP connected)
{
void* temp = null;
SocketStatus ret = sfSocketTCP_Accept(m_ptr, &temp, null);
connected.m_ptr = temp;
return ret;
}
/**
* Wait for a connection (must be listening to a port).
* This function is blocking.
*
* Params:
* connected = Socket containing the connection with the connected client
* address = Pointer to an address to fill with client infos
*
* Returns:
* Status code
*/
SocketStatus accept(SocketTCP connected, out IPAddress address)
{
void* temp = null;
SocketStatus ret = sfSocketTCP_Accept(m_ptr, &temp, &address);
connected.m_ptr = temp;
return ret;
}
/**
* Send an array of bytes to the host (must be connected first)
*
* Params:
* data = array of bytes to send
*
* Returns:
* Status code
*/
SocketStatus send(byte[] data)
{
if (data && data.length > 0)
return cast(SocketStatus)sfSocketTCP_Send(m_ptr, data.ptr, data.length);
}
/**
* Receive an array of bytes from the host (must be connected first).
* This function will block until a connection was accepted
*
* Params:
* data = array to fill (make sure it is big enough)
* sizeReceived = Number of bytes received
*
* Returns:
* Status code
*
* Remarks:
* Assert if data is null or length == 0
*
*/
SocketStatus receive(byte[] data, out size_t sizeReceived)
{
if (data && data.length > 0)
return cast(SocketStatus)sfSocketTCP_Receive(m_ptr, data.ptr, data.length, &sizeReceived);
}
/**
* Send a packet of data to the host (must be connected first)
*
* Params:
* packetToSend = Packet to send
*
* Returns:
* Status code
*
*/
SocketStatus send(Packet packetToSend)
{
byte[] dataArray = packetToSend.onSend();
m_intermediatePacket.append(dataArray);
SocketStatus stat = cast(SocketStatus)sfSocketTCP_SendPacket(m_ptr, m_intermediatePacket.getNativePointer);
m_intermediatePacket.clear();
return stat;
}
/**
* Receive a packet from the host (must be connected first).
* This function will block if the socket is blocking
*
* Params:
* packetToReceive = Packet to fill with received data
*
* Returns:
* Status code
*
*/
SocketStatus receive(Packet packetToReceive)
{
SocketStatus stat = cast(SocketStatus)sfSocketTCP_ReceivePacket(m_ptr, m_intermediatePacket.getNativePointer);
packetToReceive.onReceive(m_intermediatePacket.getData);
m_intermediatePacket.clear();
return stat;
}
/**
* Check if the socket is in a valid state ; this function
* can be called any time to check if the socket is OK
*
* Returns:
* True if the socket is valid
*
*/
bool isValid()
{
return cast(bool)sfSocketTCP_IsValid(m_ptr);
}
///
bool opEquals(SocketTCP other)
{
return (other.getNativePointer == this.getNativePointer);
}
package:
this (void* ptr)
{
super(ptr);
m_intermediatePacket = new Packet();
}
private:
Packet m_intermediatePacket;
// External ====================================================================
extern (C)
{
typedef void* function() pf_sfSocketTCP_Create;
typedef void function(void*) pf_sfSocketTCP_Destroy;
typedef int function(void*, ushort, IPAddress, float) pf_sfSocketTCP_Connect;
typedef int function(void*, ushort) pf_sfSocketTCP_Listen;
typedef SocketStatus function(void*, void**, IPAddress*) pf_sfSocketTCP_Accept;
typedef SocketStatus function(void*, byte*, size_t) pf_sfSocketTCP_Send;
typedef SocketStatus function(void*, byte*, size_t, size_t*) pf_sfSocketTCP_Receive;
typedef SocketStatus function(void*, void*) pf_sfSocketTCP_SendPacket;
typedef SocketStatus function(void*, void*) pf_sfSocketTCP_ReceivePacket;
typedef int function(void*) pf_sfSocketTCP_IsValid;
static pf_sfSocketTCP_Create sfSocketTCP_Create;
static pf_sfSocketTCP_Destroy sfSocketTCP_Destroy;
static pf_sfSocketTCP_Connect sfSocketTCP_Connect;
static pf_sfSocketTCP_Listen sfSocketTCP_Listen;
static pf_sfSocketTCP_Accept sfSocketTCP_Accept;
static pf_sfSocketTCP_Send sfSocketTCP_Send;
static pf_sfSocketTCP_Receive sfSocketTCP_Receive;
static pf_sfSocketTCP_SendPacket sfSocketTCP_SendPacket;
static pf_sfSocketTCP_ReceivePacket sfSocketTCP_ReceivePacket;
static pf_sfSocketTCP_IsValid sfSocketTCP_IsValid;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfSocketTCP_Accept = cast(pf_sfSocketTCP_Accept)dll.getSymbol("sfSocketTCP_Accept");
sfSocketTCP_Connect = cast(pf_sfSocketTCP_Connect)dll.getSymbol("sfSocketTCP_Connect");
sfSocketTCP_Create = cast(pf_sfSocketTCP_Create)dll.getSymbol("sfSocketTCP_Create");
sfSocketTCP_Destroy = cast(pf_sfSocketTCP_Destroy)dll.getSymbol("sfSocketTCP_Destroy");
sfSocketTCP_IsValid = cast(pf_sfSocketTCP_IsValid)dll.getSymbol("sfSocketTCP_IsValid");
sfSocketTCP_Listen = cast(pf_sfSocketTCP_Listen)dll.getSymbol("sfSocketTCP_Listen");
sfSocketTCP_Receive = cast(pf_sfSocketTCP_Receive)dll.getSymbol("sfSocketTCP_Receive");
sfSocketTCP_ReceivePacket = cast(pf_sfSocketTCP_ReceivePacket)dll.getSymbol("sfSocketTCP_ReceivePacket");
sfSocketTCP_Send = cast(pf_sfSocketTCP_Send)dll.getSymbol("sfSocketTCP_Send");
sfSocketTCP_SendPacket = cast(pf_sfSocketTCP_SendPacket)dll.getSymbol("sfSocketTCP_SendPacket");
}
}

View file

@ -0,0 +1,243 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.network.socketudp;
import dsfml.network.ipaddress;
import dsfml.network.packet;
import dsfml.network.socketstatus;
import dsfml.system.common;
/**
* SocketUDP wraps a socket using UDP protocol to
* send data fastly (but with less safety)
*/
class SocketUDP : DSFMLObject
{
/**
* Default constructor
*/
this()
{
super(sfSocketUDP_Create());
m_intermediatePacket = new Packet();
}
override void dispose()
{
sfSocketUDP_Destroy(m_ptr);
}
/**
* Bind the socket to a specific port
*
* Params:
* port = Port to bind the socket to
*
* Returns:
* True if operation has been successful
*
*/
bool bind(ushort port)
{
m_port = port;
return cast(bool)sfSocketUDP_Bind(m_ptr, port);
}
/**
* Unbind the socket from its previous port, if any
*
* Returns: True if operation has been successful
*
*/
bool unbind()
{
m_port = 0;
return cast(bool)sfSocketUDP_Unbind(m_ptr, m_port);
}
/**
* Send an array of bytes
*
* Params:
* data = bytes array to send
* address = Address of the computer to send the packet to
* port = Port to send the data to
*
* Returns:
* Status code
*
*/
SocketStatus send(byte[] data, IPAddress address, ushort port)
{
return cast(SocketStatus) sfSocketUDP_Send(m_ptr, data.ptr, data.length, address, port);
}
/**
* Receive an array of bytes.
* This function is blocking.
*
* Params:
* data = Pointer to a byte array to fill (make sure it is big enough)
* sizeReceived = Number of bytes received
* address = Address of the computer which sent the data
*
* Returns:
* Status code
*
* Remarks:
* Assert if data is null or length == 0
*
*/
SocketStatus receive(byte[] data, out size_t sizeReceived, out IPAddress address)
{
SocketStatus ret = sfSocketUDP_Receive(m_ptr, data.ptr, data.length, &sizeReceived, &address);
return ret;
}
/**
* Send a packet of data
*
* Params:
* packetToSend = Packet to send
* address = Address of the computer to send the packet to
* port = Port to send the data to
*
* Returns:
* Status code
*
*/
SocketStatus send(Packet packetToSend, IPAddress address, ushort port)
{
byte[] dataArray = packetToSend.onSend();
m_intermediatePacket.append(dataArray);
SocketStatus stat = cast(SocketStatus)sfSocketUDP_SendPacket(m_ptr, m_intermediatePacket.getNativePointer, address, port);
m_intermediatePacket.clear();
return stat;
}
/**
* Receive a packet.
* This function is blocking.
*
* Params:
* packetToReceive = Packet to fill with received data
* address = Address of the computer which sent the packet
*
* Returns:
* Status code
*
*/
SocketStatus receive(Packet packetToReceive, out IPAddress address)
{
SocketStatus ret = sfSocketUDP_ReceivePacket(m_ptr, m_intermediatePacket.getNativePointer, &address);
packetToReceive.onReceive(m_intermediatePacket.getData);
m_intermediatePacket.clear();
return ret;
}
/**
* Check if the socket is in a valid state ; this function
* can be called any time to check if the socket is OK
*
* Returns:
* True if the socket is valid
*
*/
bool isValid()
{
return cast(bool)sfSocketUDP_IsValid(m_ptr);
}
/**
* Get the port the socket is currently bound to
*
* Returns:
* Current port (0 means the socket is not bound)
*/
ushort getPort()
{
return m_port;
}
///
bool opEquals(SocketUDP other)
{
return (other.getNativePointer == this.getNativePointer);
}
package:
this (void* ptr)
{
super(ptr);
m_intermediatePacket = new Packet();
}
private:
Packet m_intermediatePacket;
ushort m_port;
// External ====================================================================
extern (C)
{
typedef void* function() pf_sfSocketUDP_Create;
typedef void function(void*) pf_sfSocketUDP_Destroy;
typedef int function(void*, ushort) pf_sfSocketUDP_Bind;
typedef int function(void*, ushort) pf_sfSocketUDP_Unbind;
typedef SocketStatus function(void*, byte*, size_t, IPAddress, ushort) pf_sfSocketUDP_Send;
typedef SocketStatus function(void*, byte*, size_t, size_t*, IPAddress*) pf_sfSocketUDP_Receive;
typedef SocketStatus function(void*, void*, IPAddress, ushort) pf_sfSocketUDP_SendPacket;
typedef SocketStatus function(void*, void*, IPAddress*) pf_sfSocketUDP_ReceivePacket;
typedef int function(void*) pf_sfSocketUDP_IsValid;
static pf_sfSocketUDP_Create sfSocketUDP_Create;
static pf_sfSocketUDP_Destroy sfSocketUDP_Destroy;
static pf_sfSocketUDP_Bind sfSocketUDP_Bind;
static pf_sfSocketUDP_Unbind sfSocketUDP_Unbind;
static pf_sfSocketUDP_Send sfSocketUDP_Send;
static pf_sfSocketUDP_Receive sfSocketUDP_Receive;
static pf_sfSocketUDP_SendPacket sfSocketUDP_SendPacket;
static pf_sfSocketUDP_ReceivePacket sfSocketUDP_ReceivePacket;
static pf_sfSocketUDP_IsValid sfSocketUDP_IsValid;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfSocketUDP_Bind = cast(pf_sfSocketUDP_Bind)dll.getSymbol("sfSocketUDP_Bind");
sfSocketUDP_Create = cast(pf_sfSocketUDP_Create)dll.getSymbol("sfSocketUDP_Create");
sfSocketUDP_Destroy = cast(pf_sfSocketUDP_Destroy)dll.getSymbol("sfSocketUDP_Destroy");
sfSocketUDP_IsValid = cast(pf_sfSocketUDP_IsValid)dll.getSymbol("sfSocketUDP_IsValid");
sfSocketUDP_Receive = cast(pf_sfSocketUDP_Receive)dll.getSymbol("sfSocketUDP_Receive");
sfSocketUDP_ReceivePacket = cast(pf_sfSocketUDP_ReceivePacket)dll.getSymbol("sfSocketUDP_ReceivePacket");
sfSocketUDP_Send = cast(pf_sfSocketUDP_Send)dll.getSymbol("sfSocketUDP_Send");
sfSocketUDP_SendPacket = cast(pf_sfSocketUDP_SendPacket)dll.getSymbol("sfSocketUDP_SendPacket");
sfSocketUDP_Unbind = cast(pf_sfSocketUDP_Unbind)dll.getSymbol("sfSocketUDP_Unbind");
}
}