Hi Everyone, I believe there is a bug in the Windows implementation of 
asyncnet. I cannot specify a source IP or source port using bindAddr() for use 
in a TCP client.

An extract of the problem code is below:
    
    
    import asyncdispatch, asyncnet
    import net
    
    proc client() {.async.} =
      let socket = newAsyncSocket(buffered=false)
      socket.bindAddr(Port(8888),"192.168.1.100")
      await socket.connect("example.com", Port(80))
    waitFor client()
    
    
    Run

Error:
    
    
    Error: unhandled exception: An invalid argument was supplied.
    
    Async traceback:
      C:\tmp\problemtcpclient.nim(8)                problemtcpclient
      C:\nim-1.6.12\lib\pure\asyncmacro.nim(232)     client
      C:\nim-1.6.12\lib\pure\asyncmacro.nim(28)      clientNimAsyncContinue
      C:\tmp\problemtcpclient.nim(7)                clientIter
      C:\nim-1.6.12\lib\pure\asyncmacro.nim(232)     connect
      C:\nim-1.6.12\lib\pure\asyncmacro.nim(28)      connectNimAsyncContinue
      C:\nim-1.6.12\lib\pure\asyncnet.nim(299)       connectIter
      C:\nim-1.6.12\lib\pure\asyncdispatch.nim(1856) connect
      C:\nim-1.6.12\lib\pure\asyncdispatch.nim(1684) bindToDomain
      C:\nim-1.6.12\lib\pure\includes\oserr.nim(95)  raiseOSError
      #[
        C:\tmp\problemtcpclient.nim(8)                problemtcpclient
        C:\nim-1.6.12\lib\pure\asyncmacro.nim(232)     client
        C:\nim-1.6.12\lib\pure\asyncmacro.nim(31)      clientNimAsyncContinue
        C:\nim-1.6.12\lib\pure\asyncmacro.nim(131)     clientIter
        C:\nim-1.6.12\lib\pure\asyncfutures.nim(389)   read
      ]#
    Exception message: An invalid argument was supplied.
     
     [OSError]
    
    
    Run

This issue does not occur in Linux and normal sockets (synchronous) have no 
problem using bindAddr() to specify a source IP/port with connect().

Perhaps this could be raised as an issue? In the meanwhile, any advice for a 
work around using nativesockets would be appreciated.

Thanks! H.G

Reply via email to