|
- Author:
- JJR (IP: 207.194.36.210)
- Timestamp:
- 12/02/07 07:31:25 (16 years ago)
- Comment:
concerning sockets
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ChapterNetworking
v18 |
v19 |
|
43 | 43 | In Tango the Socket class constitutes a complete wrapper for the BSD Socket API. In that sense, it is a low level network interface in Tango: despite simplifying the interface of the BSD Socket in general, using it still requires a thorough knowledge of the BSD mechanism. Here we will give an overview of how to apply the Tango Socket mechanism. For a more thorough discussion of network socket specifics, see the references at the end of this chapter. In later sections, this chapter will introduce high level network interfaces that eliminate much of the hassle of working with low-level sockets. |
---|
44 | 44 | |
---|
| 45 | === Creating the Socket === |
---|
| 46 | |
---|
| 47 | Before we can create a socket, we will need to describe how it will be used and how it will communicate with another socket. Most network programs use maybe one or two types of sockets for the majority of tasks, but flexibility demands that many options be available to the programmer. Therefore, during creation of a socket, we need to specify several socket features that define how we will later communicate through the socket. There are three types of attributes to set: |
---|
| 48 | |
---|
| 49 | * the address family |
---|
| 50 | * the socket type |
---|
| 51 | * the protocol type |
---|
| 52 | |
---|
| 53 | The address family describes how all communication points or nodes will be addressed or accessed through the new socket. For example, if we create a socket with AddressFamily.INET, then all communications through the socket are expected to use a 32-bit internet address (eg. 127.0.0.1) and a 16-bit port number. Using AddressFamily.UNIX means that we expect to communicate through the socket using a local UNIX file path descriptor as an address. Here is a list of address family's provided by the Tango Socket: |
---|
| 54 | |
---|
| 55 | * AddressFamily.UNSPEC -- not specified |
---|
| 56 | * AddressFamily.UNIX -- addresses are file paths for this socket |
---|
| 57 | * AddressFamily.INET -- addresses are 32-bit internet addresses and a port number |
---|
| 58 | * AddressFamily.IPX -- addresses use the Netware format |
---|
| 59 | * AddressFamily.APPLETALK -- addresses use the AppleTalk format |
---|
| 60 | |
---|
| 61 | Next we describe the socket type. A type specifies how the socket manages the connection or controls the flow of outgoing or incoming data. For example, choosing a STREAM type indicates that the socket will try to guarantee a reliable two-way transmission of data bytes. On the other hand, selecting the datagram (DGRAM) type indicates that we want a socket that is connectionless; that is, the socket knows nothing of an outside connection, yet sends bytes out to the specified address without any guarantee that the data is actually received or even arrives in order. These are the socket types (see references for more details): |
---|
| 62 | |
---|
| 63 | * SocketType.STREAM -- reliable two way connection |
---|
| 64 | * SocketType.DGRAM -- connectionless unreliable datagrams |
---|
| 65 | * SocketType.RAW -- raw protocol access |
---|
| 66 | * SocketType.RDM -- reliably-delivered message datagrams |
---|
| 67 | * SocketType.SEQPACKET -- sequenced, reliable, two-way connection-based datagrams |
---|
| 68 | |
---|
| 69 | -- continued -- |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
45 | 74 | == More than Sockets == |
---|
46 | 75 | |
|
|
|
|
|
Copyright © 2006-2024 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic