eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SocketAddress':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: SocketAddress


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--ArrayedCollection
            |
            +--UninterpretedBytes
               |
               +--SocketAddress
                  |
                  +--AppletalkSocketAddress
                  |
                  +--DecNetSocketAddress
                  |
                  +--IPSocketAddress
                  |
                  +--UDSocketAddress

Package:
stx:libbasic2
Category:
OS-Sockets
Version:
rev: 1.59 date: 2018/05/13 23:40:22
user: cg
file: SocketAddress.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


Abstract superclass for subclasses implementing various IPC addressing schemes.
See concrete examples IPSocketAddress and UDSocketAddress.

ST-80 compatibility class.
This may be required when existing code has to be ported to ST/X;
however, it may not be complete and more protocol may be added in the future.
The code here was created when public domain code (Manchester) had to
be ported to ST/X and missing classes/methods were encountered, and code added
by reasoning 'what the original class could probably do there'.

This is an additional goody class; therefore:

THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.


Class protocol:

addressing
o  anyAddress

instance creation
o  allForHostName: name
get a collection of new instances given a hostname

o  allForHostName: name port: portNr
get a collection of new instances given a hostname and port

o  allForHostName: name serviceName: portNrOrName domain: domainSymbol type: socketTypeSymbol
get a collection of new instances given a hostname, port or service and type.
Multi-homed hosts return more than one entry

usage example(s):

     SocketAddress allForHostName:'localhost' serviceName:10 type:#stream
     SocketAddress allForHostName:'localhost' serviceName:'10' type:#stream
     IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:#datagram 
     IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:nil
     SocketAddress allForHostName:'google.com' serviceName:'http' type:#stream
     IPSocketAddress allForHostName:'google.com' serviceName:'http' type:nil

o  allForHostName: name serviceName: portNrOrName type: socketTypeSymbol
get a collection of new instances given a hostname, port or service and type.
Multi-homed hosts return more than one entry

usage example(s):

     SocketAddress allForHostName:'localhost' serviceName:10 type:#stream
     SocketAddress allForHostName:'localhost' serviceName:'10' type:#stream
     IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:#datagram 
     IPSocketAddress allForHostName:'localhost' serviceName:'echo' type:nil
     SocketAddress allForHostName:'google.com' serviceName:'http' type:#stream
     IPSocketAddress allForHostName:'google.com' serviceName:'http' type:nil

o  anyHost
get a new instance representing the ANY-host address

o  fromBytes: bytesArg
create a socket address from bytes (ByteArray),
returned by the primitive syscalls.
Raises an error, if the domainType is not supported by this Smalltalk
(i.e. if libbasic was compiled without support for the corresponding AF_xxx support)

o  hostAddress: addr
get a new instance given addr-bytes

usage example(s):

     IPSocketAddress hostAddress:#[127 0 0 1]

o  hostAddress: addr port: portNr
get a new instance given addr-bytes and a portNr

o  hostName: name
get a new instance given a hostname

o  hostName: name port: portNr
get a new instance given a hostname and port

o  hostName: name serviceName: portNrOrName type: socketTypeSymbol
get a new instance given a hostname, port or service and type.
Do not use this, since it does not work for multi-homed hosts

usage example(s):

     SocketAddress hostName:'localhost' serviceName:10 type:#stream  
     IPSocketAddress hostName:'localhost' serviceName:'echo' type:#datagram 
     IPSocketAddress hostName:'localhost' serviceName:'echo' type:nil
     IPSocketAddress hostName:'www.google.com' serviceName:'http' type:nil
     SocketAddress allForHostName:'localhost' serviceName:10 type:#stream.
     SocketAddress allForHostName:'www.google.com' serviceName:10 type:#stream.

o  new
IPSocketAddress new
IPv6SocketAddress new
UDSocketAddress new
AppletalkSocketAddress new

o  newDomain: domain
answer an new socket address for a given domain

usage example(s):

    self newDomain:#afUnix    
    self newDomain:#afInet    

    self newDomain:#'AF_UNIX' 
    self newDomain:#'AF_INET' 

    self newDomain:#unix
    self newDomain:#inet

queries
o  domain
Answer the domain symbol. Subclasses redefine this

** This method raises an error - it must be redefined in concrete classes **

o  domainCode
answer the numerical domain code used in socket addresses

o  domainCodeFromName: aNameSymbol
this is a compatibility method;
VW returns the internal unix codes here - however, in ST/X,
symbols are returned, which are translated later

o  domainNameFromCode: code
this is a compatibility method;
VW expects the internal unix codes here - however, in ST/X,
symbols are expected - keeping the numeric values secret (in Socket)

o  getAddressInfo: hostName serviceName: serviceName domain: domainArg type: typeArg protocol: protoArg flags: flags
answer an Array of socket addresses for serviceName on hostName
Domain, type, protocol may be nil or specify a hint for the socket
addresses to be returned.

usage example(s):

     self getAddressInfo:'localhost' serviceName:nil 
            domain:nil type:nil protocol:nil flags:nil
     self getAddressInfo:'localhost' serviceName:nil 
            domain:#AF_INET type:#stream protocol:nil flags:nil
     self getAddressInfo:'localhost' serviceName:nil 
            domain:#AF_INET type:#stream protocol:#tcp flags:nil
     self getAddressInfo:'blurb.exept.de' serviceName:nil 
            domain:#AF_INET type:nil protocol:nil flags:nil
     self getAddressInfo:'1.2.3.4' serviceName:'6' 
            domain:#AF_INET type:nil protocol:nil flags:nil
     self getAddressInfo:'localhost' serviceName:'echo' 
            domain:#AF_INET6 type:nil protocol:nil flags:nil

o  getAddressInfo: hostName serviceName: serviceName type: typeArg protocol: protoArg flags: flags
answer an Array of socket addresses for serviceName on hostName
Domain, type, protocol may be nil or specify a hint for the socket
addresses to be returned.

usage example(s):

     IPSocketAddress getAddressInfo:'localhost' serviceName:nil 
                     type:nil protocol:nil flags:nil
     IPSocketAddress getAddressInfo:'localhost' serviceName:nil 
                     type:#stream protocol:nil flags:nil
     IPSocketAddress getAddressInfo:'localhost' serviceName:nil 
                     type:#stream protocol:#tcp flags:nil
     IPSocketAddress getAddressInfo:'blurb.exept.de' serviceName:nil 
                     type:nil protocol:nil flags:nil
     IPSocketAddress getAddressInfo:'1.2.3.4' serviceName:'6' 
                     type:nil protocol:nil flags:nil
     IPSocketAddress getAddressInfo:'localhost' serviceName:'echo' 
                     type:nil protocol:nil flags:nil

o  getNameInfo: socketAddress wantHostName: wantHostName wantServiceName: wantServiceName datagram: useDatagram flags: flags
answer an Array containing the hostName and/or serviceName
for a given socketAddress.

usage example(s):

     self getNameInfo:
         (self getAddressInfo:'localhost' serviceName:'echo' 
                domain:#inet type:#stream protocol:nil flags:nil) first socketAddress
         wantHostName:true wantServiceName:true datagram:false flags:0     

o  hostAddressLen
answer the number of bytes of the host address

** This method raises an error - it must be redefined in concrete classes **

o  isAbstract
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.

o  knownClassFromCode: code
this is a compatibility method;
VW expects the internal unix codes here - however, in ST/X,
symbols are expected - keeping the numeric values secret (in Socket)

usage example(s):

     DomainToClassMapping := nil.

     self knownClassFromCode:#'AF_UNIX' 
     self knownClassFromCode:#'AF_INET'

     self knownClassFromCode:1
     self knownClassFromCode:2

     self knownClassFromCode:#unix             obsolete ST/X codes
     self knownClassFromCode:#inet

     self knownClassFromCode:#afUnix           visualWorks codes
     self knownClassFromCode:#afInet

o  obsoleteDomainSymbol

o  peerNameFromPeer: peer

o  socketAddressSize
answer the OS specific size of a socket address.
Returns nil, if the domain is not supported or invalid.

usage example(s):

     SocketAddress socketAddressSize  
     UDSocketAddress socketAddressSize  
     IPSocketAddress socketAddressSize  
     IPv6SocketAddress socketAddressSize 
     AppletalkSocketAddress socketAddressSize  
     DecNetSocketAddress socketAddressSize     

o  vwDomainSymbol


Instance protocol:

accessing
o  domainCode
this opaquely returns the first two bytes as a short integer;
Notice: some systems store the domainCode in those 2 bytes,
whereas others (IOS) store the size of the addr-struct in byte 1,
and the actual domain code in byte 2

o  domainCode: anInteger
this opaquely sets the first two bytes as a short integer;
Notice: some systems store the domainCode in those 2 bytes,
whereas others (IOS) store the size of the addr-struct in byte 1,
and the actual domain code in byte 2

o  hostAddress: addressBytes
generic method, subclasses usually redefine this

usage example(s):

     IPSocketAddress hostAddress:#[193 141 12 193] port:80

o  hostAddress: addressBytes port: portNr
IPSocketAddress hostAddress:#[193 141 12 193] port:10

o  hostAddressString

o  port

o  port: portNr

comparing
o  sameHostAddress: aSocketAddress
answer true, if aSocketAddres has the same hostaddress as myself

usage example(s):

     (IPSocketAddress hostAddress:#[193 141 12 193] port:80)
        sameHostAddress:
     (IPSocketAddress hostAddress:#[193 141 12 193] port:81)

converting
o  asIPv4SocketAddressIfPossible

hashing
o  hash
generate a SmallInteger hash for the socket address - use all the bytes

printing & storing
o  displayOn: aGCOrStream
redefine from Collection

o  inspectorValueStringInListFor: anInspector
( an extension from the stx:libtool package )
returns a string to be shown in the inspector's list

o  printAddressOn: arg
raise an error: must be redefined in concrete subclass(es)

** This method raises an error - it must be redefined in concrete classes **

o  printOn: aStream
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.

o  printOn: aStream withPort: withPort
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.

o  printPortOn: aStream

private
o  fromBytes: aByteArray
Copy the internal representation of a SocketAddress to myself

This is an internal interface!

queries
o  address

o  domain
anwer the domain symbol used to creat a socket

o  hostName
(IPSocketAddress hostAddress:#[127 0 0 1]) hostName
(IPSocketAddress hostName:'localhost') address
(IPSocketAddress hostName:'www.google.com') address

(IPSocketAddress hostAddress:#[127 0 0 1] port:7) hostName
(IPSocketAddress hostAddress:#[172 23 1 1] port:10) hostName
(IPSocketAddress hostAddress:#[172 24 1 244]) hostName
(IPv6SocketAddress hostAddress: #[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]) hostName
(IPv6SocketAddress hostAddress: #[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2]) hostName
(IPv6SocketAddress hostAddress: #[0 0 0 0 0 0 0 0 0 0 255 255 127 0 0 1]) hostName
(IPv6SocketAddress hostAddress: #[0 0 0 0 0 0 0 0 0 0 255 255 172 23 1 1]) hostName

o  hostNameOrAddressString
answer the host name or the string representation
of the address

usage example(s):

        (IPSocketAddress hostName:'localhost') hostNameOrAddressString
        (IPSocketAddress hostAddress:#[192 168 8 33]) hostNameOrAddressString

o  portOrName

o  serviceName
(IPSocketAddress hostAddress:#[127 0 0 1] port:7) serviceName
(IPSocketAddress hostAddress:#[193 141 12 193] port:10) serviceName

testing
o  isIPSocketAddress

o  isIPv4SocketAddress

o  isIPv6SocketAddress

o  isLocal
answer true, if this address addresses a peer on the same host

** This method raises an error - it must be redefined in concrete classes **

o  isMyAddress
answer true, if the address refers to my own host.
Subclasses may redefine this to check the local configuration, too.

o  isSocketAddress



ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 25 Apr 2024 08:25:56 GMT