Socket.Disconnect(bool reuse)
according to MSDN enables the program to reuse the socket. My questions are:
If we decide to reuse the socket does that mean it will reuse the same local end point as well? Would it preserve the port for that socket or would it just (I don't believe it does) save all the objects resources?
If in effect it does only save the resources would they be allocated to the next connection and if so do the send/receive buffers automaticly flush or is there some way the flush them? Does Socket.ShutDown(ShutDown.Both)
do that for me on disconnect?
In what situation would I use Socket.Disconnect(false)
? If all the purpose is to reuse the socket what would this grant me?
If reuse = false the socket will be disposed automatically after closing. All settings as EndPoint and Buffer sizes are not reseted to defaults, but you can change it if you desire. Supose the user decides to change the connection port. You just need to close the socket, change the port and connect the socket again without create a new socket and set it up again.
The Socket.Shutdown just disables send/receive/both; not disconnect the socket. However this occurs for new incoming/outgoing data so buffers will be flushed normaly. It is a good practice to call it before disconnection to ensure all data was sent and no data is being received while disconnecting.
Returning to the example of 1. Supose you need to change only the port. You dont want to create the socket again, configure all parameters of the socket as events and buffers again, etc. It consumes time and resources, so it is better to reuse the socket you already have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With