question

WaiteJooyoun-0064 avatar image
0 Votes"
WaiteJooyoun-0064 asked TimonYang-MSFT commented

How to form optionInValue to set 'ioControlCode==KeepAliveValues'

Hello MSDN or community.

I would like ask how to use Socket.IOControl Method.

Specifically, I want to try to send TCP socket keepalive packet every 30 sec to remote host.

I referred below MSDN documentation but I couldn't figure out how to from below page.
https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.iocontrol?view=net-5.0&source=docs#System_Net_Sockets_Socket_IOControl_System_Int32_System_Byte_System_Byte_


I figured I have to refer below method from myClient.
myClient.IOControl(IOControlCode.KeepAliveValues, optionInValue(??) , null);

But I couldn't figure out how I should create optionInValue in byte[ ] from given MSDN documentation?

If you teach me how to refer MSDN document, it would be appreciated.

My project is C# and using .net framework version 4.0

Thank you in advance.
Joo

dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@WaiteJooyoun-0064
Please see if the example in the link below might help:
SetSocketKeepAliveValues

0 Votes 0 ·

1 Answer

WaiteJooyoun-0064 avatar image
0 Votes"
WaiteJooyoun-0064 answered TimonYang-MSFT commented

@TimonYang-MSFT

Thank you for your comment. I want able to send keep alive packet in my client code.

This is slightly different question but if you have answer, can you teach me how to utilize or refer microsoft documentations?


Because I think I found correct method reference document what I need to use, which is 'IOControl' in dotnet.

And IOControl optionInValue/optionOutValue parameter is utilized based on IoControlCode. Or caller should provision different size of buffer based on IoControlCode value.

There are many IoControlCode values are defined but I couldn't figure out what is the size in byte buffer Inbuffer, Outbuffer based on IoControlCode.


I would like to learn how to refer msdn documentation, IOControl, as an example.

https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.iocontrol?view=net-5.0&source=docs#System_Net_Sockets_Socket_IOControl_System_Int32_System_Byte_System_Byte_


Thank you in advance

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have no experience in using this method, but according to the code samples I have seen, the length of inOptionValues is mostly set to 12.
Please check the many examples in this link, most of which are SetKeepAlive examples. Is there a suitable one for you?
System.Net.Sockets.Socket.IOControl()

0 Votes 0 ·

Thank you very much for your responses. It helped me a lot. Cheers!

0 Votes 0 ·

@WaiteJooyoun-0064
You are welcome.

0 Votes 0 ·