Socket2>>connect

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Socket2>>connect

Steve Alan Waring
Would it be possible to refactor Socket2>>connect to make it easier to
configure the socket between Socket2>>create and the call to the connect()
function.

For example: I need to create a Socket and bind it to a specific ip address
on a machine with multiple IP addresses. Without specifically binding it to
one ip address, Windows seems to randomly pick one. The call to the bind
function needs to take place after creation and before connect(). To achieve
this, I would need to duplicate most of the Socket2>>connect method.

A nice solution would be if (in the Socket2>>connect method) everything
after the "self create." statement was extracted to a new method (say
#basicConnect ... although that may cause confusion c.w.
Socket>>basicConnect).

Then I could write something like:

socket
  create;
  bindTo: '1.2.3.4';
  basicConnect.


FWIW: The method I used to bind in the old sockets package was:

bindTo: anIPString
 | result socketAddress |
 socketAddress := SOCKADDR_IN new.
 socketAddress sin_family: AF_INET.
 socketAddress sin_addr: (IN_ADDR address: (InternetAddress fromIPString:
anIPString)).
 socketAddress sin_port: (WSockLibrary default htons: 0).
 result := WSockLibrary default
    bind: self asParameter
    addr: socketAddress asParameter
    namelen: socketAddress byteSize.
 result = 0 ifFalse: [self error]! !

Steve
--
Steve Waring
[hidden email]