Your TimerTimeout function call is correctly setting the timeout, but it may not be applied to the MsgSend operation as expected. The following areas should be focused to fix the issue,
Ensure Timeout is Set Before MsgSend The TimerTimeout function sets a timeout for a specific thread, but it applies to the next blocking operation on that thread. If TimerTimeout is called but another blocking operation occurs before MsgSend, the timeout might not be applied. Make sure TimerTimeout is called immediately before MsgSend.
Check Server Delay Your server sleeps for 10 seconds, but your client timeout is 2 seconds. If TimerTimeout is properly set, MsgSend should return with ETIMEDOUT