AppletalkSocketAddress.st
changeset 818 2f8331ad12d4
parent 815 cb36489446b2
child 1162 c8ba14f81f13
--- a/AppletalkSocketAddress.st	Tue Sep 21 01:58:18 1999 +0200
+++ b/AppletalkSocketAddress.st	Tue Sep 21 02:27:27 1999 +0200
@@ -11,8 +11,8 @@
 "
 
 
-SocketAddress subclass:#AppletalkSocketAddress
-	instanceVariableNames:'port address'
+SocketAddress variableByteSubclass:#AppletalkSocketAddress
+	instanceVariableNames:'port'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'OS-Sockets'
@@ -52,6 +52,12 @@
 "
 ! !
 
+!AppletalkSocketAddress class methodsFor:'instance creation'!
+
+new
+    ^ self new:3
+! !
+
 !AppletalkSocketAddress class methodsFor:'queries'!
 
 hostAddressByName: hostName
@@ -74,36 +80,45 @@
 
 ! !
 
-!AppletalkSocketAddress methodsFor:'queries'!
-
-hostAddress:anAddress
-    address := anAddress
-
-!
-
-hostName
-    ^ Socket hostWithAppletalkAddress:address
-
-
-!
+!AppletalkSocketAddress methodsFor:'accessing'!
 
 net
-    ^ address wordAt:1 MSB:true
+    ^ ((self at:1) bitShift:8) bitOr:(self at:2)
 
 
 !
 
 net:aNodeAddress
-    address isNil ifTrue:[
-        address := ByteArray new:3
-    ].
-    address at:3 put:aNodeAddress
+    self at:1 put:((aNodeAddress bitShift:-1) bitAnd:16rFF).
+    self at:2 put:(aNodeAddress bitAnd:16rFF).
+
+    "
+     self new net:16r1234
+    "
+!
+
+net:netNr node:nodeNr port:portNr
+    self 
+        net:netNr;
+        node:nodeNr;
+        port:portNr
+
+    "
+     AppletalkSocketAddress new net:1234 node:10 port:20
+    "
+    "
+     AppletalkSocketAddress hostAddress:#[1 2 3] port:10
+    "
+!
+
+node
+    ^ self at:3
 
 
 !
 
-node
-    ^ address at:3
+node:aNodeNr
+    self at:3 put:aNodeNr
 
 
 !
@@ -113,6 +128,36 @@
 
 !
 
+port:aPortNr
+    port := aPortNr
+
+! !
+
+!AppletalkSocketAddress methodsFor:'printing & storing'!
+
+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."
+
+    self net printOn:aStream.
+    aStream nextPut:$:.
+    self node printOn:aStream.
+    port notNil ifTrue:[
+        aStream nextPut:$:.
+        port printOn:aStream.
+    ].
+
+
+! !
+
+!AppletalkSocketAddress methodsFor:'queries'!
+
+hostName
+    ^ Socket hostWithAppletalkAddress:self
+
+
+!
+
 portOrName
     ^ port
 
@@ -121,5 +166,5 @@
 !AppletalkSocketAddress class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/AppletalkSocketAddress.st,v 1.1 1999-09-20 23:53:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/AppletalkSocketAddress.st,v 1.2 1999-09-21 00:27:14 cg Exp $'
 ! !