[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The EN Network Driver consists of two components.
Note: Some operating systems may not support all the functions of this plugin.
CreateSocket()
call. The Network Driver calls
appropriate socket startup/shutdown calls for the operating system.
CreateSocket()
call located in the Network Driver. The
Socket Driver supports the following features (some might not work on all
operating systems):
The Network Driver is used to setup the socket sub-system. The driver's purpose is to provide a method for creating a BSD sockets compliant socket of either UDP or TCP type. Upon construction all appropriate socket start-up calls are made, like wise with the destructor.
CreateSocket()
LastError()
The Socket Driver is used to supply a common interface to a low-level TCP/IP network connection. It allows connecting/accepting TCP and UDP based socket connections. It provides very basic BSD compliant functionality.
LastError()
LastOSError()
IsConnected()
SetSocketBlock()
SetSocketReuse()
Connect()
Send()
Recv()
Close()
Disconnect()
WaitForConnection()
Accept()
set()
ReadLine()
RemoteName()
Here is a simple example showing the module in use.
#include "inetwork/driver2.h" #include "inetwork/socket2.h" #include "inetwork/sockerr.h" csRef<iNetworkDriver2> netdriver; csRef<iSocketDriver2> client; csRef<iSocketDriver2> server; ... netdriver = CS_QUERY_REGISTRY(object_reg, iNetworkDriver2); if (!netdriver) { ... } // Create TCP socket. server = netdriver->CreateSocket(CS_NET_SOCKET_TYPE_TCP); // Last error is netdriver->LastError(). if (server) { server->SetSocketReuse(true); if (server->LastError() != CS_NET_SOCKET_NOERROR) printf("Unable to set reuse option.\n"); server->SetSocketBlock(true); if (server->LastError() != CS_NET_SOCKET_NOERROR) printf("Unable to set block option.\n"); // Wait on port 9999 queue up to 5 connections. server->WaitForConnection(0, 9999, 5); if (server->LastError() != CS_NET_SOCKET_NOERROR) printf("Unable to bind to port.\n"); } ... if (server) { client = server->Accept(); if (client != 0) { // We have a connection. client->Send("hello\r\n",7); client->Disconnect(); } server->Close(); } |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |