Class DSocket

Inherits from:
Object
Declared in:
DSocket.h

Class Hierarchy

    Object
      |
      +---DSocket

Class Description

The DSocket class implements a number of methods for using network sockets.

Example:
#include <stdio.h>
#include "ofc/DSocket.h"
#include "ofc/DSocketAddress.h"
#include "ofc/DData.h"

int main(int argc, char *argv[])
{
  DSocket            *client = [DSocket new];
  DInetSocketAddress *addr   = [DInetSocketAddress new];

                                       // Setup a client
  [addr loopback :7000];               // Setup an address to localhost, port 7000

  printf("Open the socket ..\n");
  [client open :[addr family] :DSK_STREAM :[DSocket protocol :"tcp"]]; // Open the socket for tcp

  [client reuseAddr :YES];             // Socketoption: Reuse the socket

  printf("Wait for connection with the server..\n");
  if ([client connect :addr])          // Try to connect to the server
  {
    DData *received;

    printf("Send data to the server..\n");
    if (![client send :"Hello there .." :14 :0]) // Send data to server
      printf("Error sending data to server:%d\n", [client error]);

    printf("Receive data from the server..\n");
    received = [client recv :256 :0];            // Receive data from server

    if (received != nil)
    {
      printf("Length of received data:%ld\n", [received length]);

      [received free];
    }
    else
      printf("Error receiving data from server:%d\n", [client error]);

    printf("Close the connection..\n");
    [client shutdown :DSK_SHUT_RDWR];  // Shutdown connection

    [client close];                    // Close socket
  }
  else
    printf("No connection to the server:%d\n", [client error]);

  [client free];                       // Cleanup
  [addr   free];

  return 0;
}
Last modified:
16-Aug-2008 (DSocket.h)

Instance Variables

private int _socket
the socket
private id <DSocketAddressable> _address
the address (reference)
private int _family
the socket family (DSA_AF_INET,DSA_AF_UNIX)
private int _type
the socket type
private int _protocol
the socket protocol
private BOOL _blocking
is the socket blocking ?
private int _errno
the last error

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0