Go
Go
Move a Connection into Another Socket
See more Socket/SSL/TLS Examples
Demonstrates Socket.TakeConnection, which moves the active connection from one Socket into another. The receiving object first releases any connection it previously held.
Background. Unlike TakeSocket, TakeConnection does not add a member to a socket set. After success, the source socket holds no connection. This is useful for handing an accepted connection to a dedicated handler object.
Chilkat Go Downloads
success := false
listenSock := chilkat.NewSocket()
success = listenSock.BindAndListen(5000,25)
if success == false {
fmt.Println(listenSock.LastErrorText())
listenSock.DisposeSocket()
return
}
connectedSock := chilkat.NewSocket()
success = listenSock.AcceptNext(20000,connectedSock)
if success == false {
fmt.Println(listenSock.LastErrorText())
listenSock.DisposeSocket()
connectedSock.DisposeSocket()
return
}
// Move the active connection out of connectedSock and into another Socket object. Unlike
// TakeSocket, this does not add a member to a socket set. After success, connectedSock holds no
// connection.
handlerSock := chilkat.NewSocket()
success = handlerSock.TakeConnection(connectedSock)
if success == false {
fmt.Println(handlerSock.LastErrorText())
listenSock.DisposeSocket()
connectedSock.DisposeSocket()
handlerSock.DisposeSocket()
return
}
fmt.Println("Connection moved to the handler socket.")
listenSock.DisposeSocket()
connectedSock.DisposeSocket()
handlerSock.DisposeSocket()