How to use createTransport with new version of Network.Transport.TCP?

151 Views Asked by At

I used the network-transport-tcp-0.5.1 for creatipn TCP transport.

resultCT <- createTransport host port defaultTCPParameters

But now I'm using the package network-transport-tcp-0.6.0 and getting an error because of the new type:

createTransportExposeInternals
  :: N.HostName
  -> N.ServiceName
  -> (N.ServiceName -> (N.HostName, N.ServiceName))
  -> TCPParameters
  -> IO (Either IOException (Transport, TransportInternals))

How can I use default value for (N.ServiceName -> (N.HostName, N.ServiceName))? Maybe there are some examples? Thank you!

1

There are 1 best solutions below

0
On BEST ANSWER

When you choose a port, createTransport might not use the given port. For example, you might use the port "0", which means that any port might get used. Depending on the used port, the external host name or service can differ vastly. For example, your firewall will only forward the ports 1000-2000 on a.qspider, and 2000-3000 on b.qspider. Therefore, if you bind on 1320, your external host and service name would be a.qspider:1320.

Alternatively, you have configured your ports to forward 8080 to 80 externally, so the ServiceName 8080 would result in 80 + external address.

All in all the additional parameter provides you a method to handle external port forwardings and host names correctly. If you don't have any external networks at that point, you can simply use

createTransport host port (\port' -> (host, port')) ...