835 Set aDomainSymbolOrNil to #AF_INET of #AF_INET6 to connect via a defined protocol. |
835 Set aDomainSymbolOrNil to #AF_INET of #AF_INET6 to connect via a defined protocol. |
836 Set aDomainSymbolOrNil to nil, to try all protocols. |
836 Set aDomainSymbolOrNil to nil, to try all protocols. |
837 If the millis arg is nonNil, stop trying to connect after that many milliseconds |
837 If the millis arg is nonNil, stop trying to connect after that many milliseconds |
838 and return nil." |
838 and return nil." |
839 |
839 |
840 |socket addressInfoList| |
840 |socket addressList lastDomainSymbol| |
841 |
841 |
842 hostNameOrAddress isString ifFalse:[ |
842 hostNameOrAddress isString ifFalse:[ |
843 ^ self newTCPclientToAddress:hostNameOrAddress port:aPortOrServiceName withTimeout:millis. |
843 ^ self newTCPclientToAddress:hostNameOrAddress port:aPortOrServiceName withTimeout:millis. |
844 ]. |
844 ]. |
845 |
845 |
846 addressInfoList := SocketAddress |
846 addressList := SocketAddress |
847 getAddressInfo:hostNameOrAddress |
847 allForHostName:hostNameOrAddress |
848 serviceName:aPortOrServiceName |
848 serviceName:aPortOrServiceName |
849 domain:aDomainSymbolOrNil |
849 domain:aDomainSymbolOrNil |
850 type:#stream |
850 type:#stream. |
851 protocol:nil |
851 |
852 flags:0. |
852 addressList do:[:eachAddress| |
853 |
853 |domainSymbol| |
854 addressInfoList do:[:eachAddressInfo| |
854 |
855 |domainSymbol lastDomainSymbol| |
855 domainSymbol := eachAddress domain. |
856 |
|
857 domainSymbol := eachAddressInfo domain. |
|
858 domainSymbol ~~ lastDomainSymbol ifTrue:[ |
856 domainSymbol ~~ lastDomainSymbol ifTrue:[ |
859 socket notNil ifTrue:[ |
857 socket notNil ifTrue:[ |
860 socket close. |
858 socket close. |
861 ]. |
859 ]. |
862 socket := self new domain:domainSymbol type:#stream. |
860 socket := self new domain:domainSymbol type:#stream. |
863 lastDomainSymbol := domainSymbol. |
861 lastDomainSymbol := domainSymbol. |
864 ]. |
862 ]. |
865 (socket connectTo:eachAddressInfo socketAddress withTimeout:millis) ifTrue:[ |
863 (socket connectTo:eachAddress withTimeout:millis) ifTrue:[ |
866 ^ socket. |
864 ^ socket. |
867 ]. |
865 ]. |
868 ]. |
866 ]. |
869 socket notNil ifTrue:[ |
867 socket notNil ifTrue:[ |
870 socket close. |
868 socket close. |
876 Socket newTCPclientToHost:'www.exept.de' port:80 domain:#'AF_INET6' withTimeout:1000. |
874 Socket newTCPclientToHost:'www.exept.de' port:80 domain:#'AF_INET6' withTimeout:1000. |
877 Socket newTCPclientToHost:'www.exept.de' port:80 domain:nil withTimeout:1000. |
875 Socket newTCPclientToHost:'www.exept.de' port:80 domain:nil withTimeout:1000. |
878 Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:1000 |
876 Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:1000 |
879 " |
877 " |
880 |
878 |
881 "Modified: / 16.1.1998 / 09:47:06 / stefan" |
879 "Modified: / 21-02-2017 / 21:36:16 / stefan" |
882 ! |
880 ! |
883 |
881 |
884 newTCPclientToHost:hostNameOrAddress port:aPortOrServiceName withTimeout:millis |
882 newTCPclientToHost:hostNameOrAddress port:aPortOrServiceName withTimeout:millis |
885 "create a new TCP client socket connecting to a service on hostNameOrAddress. |
883 "create a new TCP client socket connecting to a service on hostNameOrAddress. |
886 If hostNameOrAddress is a string, try all the resolved addresses regardless |
884 If hostNameOrAddress is a string, try all the resolved addresses regardless |