diff --git a/snippets/cpp/VS_Snippets_Remoting/Socket_Socket_Options/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Socket_Socket_Options/CPP/source.cpp
index 8d52d9461b9..11687431bce 100644
--- a/snippets/cpp/VS_Snippets_Remoting/Socket_Socket_Options/CPP/source.cpp
+++ b/snippets/cpp/VS_Snippets_Remoting/Socket_Socket_Options/CPP/source.cpp
@@ -10,95 +10,96 @@ using namespace System::Threading;
public ref class Sync_Send_Receive
{
public:
- static void SetSocketOptions()
- {
- IPHostEntry^ lipa = Dns::Resolve( "host.contoso.com" );
- IPEndPoint^ lep = gcnew IPEndPoint( lipa->AddressList[ 0 ],11000 );
- Socket^ s = gcnew Socket( lep->Address->AddressFamily, SocketType::Stream,ProtocolType::Tcp );
-
-//
- // Specifies that send operations will time-out
- // if confirmation is not received within 1000 milliseconds.
- s->SetSocketOption( SocketOptionLevel::Socket, SocketOptionName::SendTimeout, 1000 );
-
- // Specifies that the Socket will linger for 10 seconds after Close is called.
- LingerOption^ lingerOption = gcnew LingerOption( true,10 );
-
- s->SetSocketOption( SocketOptionLevel::Socket, SocketOptionName::Linger, lingerOption );
-//
-
- s->Connect( lep );
-
- array^ msg = Encoding::ASCII->GetBytes( "This is a test" );
-
-//
- Console::Write( "This application will timeout if Send does not return within " );
- Console::WriteLine( Encoding::ASCII->GetString( s->GetSocketOption( SocketOptionLevel::Socket, SocketOptionName::SendTimeout, 4 ) ) );
-
- // Blocks until send returns.
- int i = s->Send( msg );
-
- // Blocks until read returns.
- array^ bytes = gcnew array(1024);
-
- s->Receive( bytes );
-
- //Displays to the screen.
- Console::WriteLine( Encoding::ASCII->GetString( bytes ) );
- s->Shutdown( SocketShutdown::Both );
- Console::Write( "If data remains to be sent, this application will stay open for " );
- Console::WriteLine( safe_cast(s->GetSocketOption( SocketOptionLevel::Socket, SocketOptionName::Linger ))->LingerTime.ToString() );
- s->Close();
-//
- }
-
- static void CheckProperties()
- {
- IPHostEntry^ lipa = Dns::Resolve( "host.contoso.com" );
- IPEndPoint^ lep = gcnew IPEndPoint( lipa->AddressList[ 0 ],11000 );
-
-//
- Socket^ s = gcnew Socket( lep->Address->AddressFamily,SocketType::Stream,ProtocolType::Tcp );
-
- //Uses the AddressFamily, SocketType, and ProtocolType properties.
- Console::Write( "I just set the following properties of socket: \n" );
- Console::Write( "Address Family = {0}", s->AddressFamily.ToString() );
- Console::Write( "\nSocketType = {0}", s->SocketType.ToString() );
- Console::WriteLine( "\nProtocolType = {0}", s->ProtocolType.ToString() );
-//
-
-//
- s->Connect( lep );
-
- // Uses the RemoteEndPoint property.
- Console::WriteLine( "I am connected to {0} on port number {1}",
- IPAddress::Parse( ( ( (IPEndPoint^)(s->RemoteEndPoint) )->Address)->ToString() ),
- ( (IPEndPoint^)(s->RemoteEndPoint) )->Port.ToString() );
-
- // Uses the LocalEndPoint property.
- Console::Write( "My local IpAddress is : {0}\nI am connected on port number {1}",
- IPAddress::Parse( ( ( (IPEndPoint^)(s->LocalEndPoint) )->Address)->ToString() ),
- ( (IPEndPoint^)(s->LocalEndPoint) )->Port.ToString() );
-//
-
-//
- //Uses low level method IOControl to set this socket to blocking mode.
- int code = 0x8004667E;
- array^ inBuf = gcnew array(4);
-
- inBuf[ 0 ] = 0;
-
- array^ outBuf = gcnew array(4);
-
- s->IOControl( code, inBuf, outBuf );
-
- //Checks to see that this worked.
- if ( s->Blocking )
- {
- Console::WriteLine( "Socket was set to Blocking mode successfully" );
- }
-//
- }
+ static void SetSocketOptions()
+ {
+ IPHostEntry^ lipa = Dns::Resolve("host.contoso.com");
+ IPEndPoint^ lep = gcnew IPEndPoint(lipa->AddressList[0], 11000);
+ Socket^ s = gcnew Socket(lep->Address->AddressFamily, SocketType::Stream, ProtocolType::Tcp);
+
+ //
+ // Specifies that send operations will time-out
+ // if confirmation is not received within 1000 milliseconds.
+ s->SetSocketOption(SocketOptionLevel::Socket, SocketOptionName::SendTimeout, 1000);
+ //
+
+ //
+ // Specifies that the Socket will linger for 10 seconds after Close is called.
+ LingerOption^ lingerOption = gcnew LingerOption(true, 10);
+ s->SetSocketOption(SocketOptionLevel::Socket, SocketOptionName::Linger, lingerOption);
+ //
+
+ s->Connect(lep);
+
+ array^ msg = Encoding::ASCII->GetBytes("This is a test");
+
+ //
+ Console::Write("This application will timeout if Send does not return within ");
+ Console::WriteLine(Encoding::ASCII->GetString(s->GetSocketOption(SocketOptionLevel::Socket, SocketOptionName::SendTimeout, 4)));
+
+ // Blocks until send returns.
+ int i = s->Send(msg);
+
+ // Blocks until read returns.
+ array^ bytes = gcnew array(1024);
+
+ s->Receive(bytes);
+
+ // Displays to the screen.
+ Console::WriteLine(Encoding::ASCII->GetString(bytes));
+ s->Shutdown(SocketShutdown::Both);
+ Console::Write("If data remains to be sent, this application will stay open for ");
+ Console::WriteLine(safe_cast(s->GetSocketOption(SocketOptionLevel::Socket, SocketOptionName::Linger))->LingerTime.ToString());
+ s->Close();
+ //
+ }
+
+ static void CheckProperties()
+ {
+ IPHostEntry^ lipa = Dns::Resolve("host.contoso.com");
+ IPEndPoint^ lep = gcnew IPEndPoint(lipa->AddressList[0], 11000);
+
+ //
+ Socket^ s = gcnew Socket(lep->Address->AddressFamily, SocketType::Stream, ProtocolType::Tcp);
+
+ // Uses the AddressFamily, SocketType, and ProtocolType properties.
+ Console::Write("I just set the following properties of socket: \n");
+ Console::Write("Address Family = {0}", s->AddressFamily.ToString());
+ Console::Write("\nSocketType = {0}", s->SocketType.ToString());
+ Console::WriteLine("\nProtocolType = {0}", s->ProtocolType.ToString());
+ //
+
+ //
+ s->Connect(lep);
+
+ // Uses the RemoteEndPoint property.
+ Console::WriteLine("I am connected to {0} on port number {1}",
+ IPAddress::Parse((((IPEndPoint^)(s->RemoteEndPoint))->Address)->ToString()),
+ ((IPEndPoint^)(s->RemoteEndPoint))->Port.ToString());
+
+ // Uses the LocalEndPoint property.
+ Console::Write("My local IpAddress is : {0}\nI am connected on port number {1}",
+ IPAddress::Parse((((IPEndPoint^)(s->LocalEndPoint))->Address)->ToString()),
+ ((IPEndPoint^)(s->LocalEndPoint))->Port.ToString());
+ //
+
+ //
+ // Uses low level method IOControl to set this socket to blocking mode.
+ int code = 0x8004667E;
+ array^ inBuf = gcnew array(4);
+
+ inBuf[0] = 0;
+
+ array^ outBuf = gcnew array(4);
+
+ s->IOControl(code, inBuf, outBuf);
+
+ // Checks to see that this worked.
+ if (s->Blocking)
+ {
+ Console::WriteLine("Socket was set to Blocking mode successfully");
+ }
+ //
+ }
};
-int main(){}
+int main() {}
diff --git a/snippets/csharp/System.Net.Sockets/LingerOption/LingerTime/source.cs b/snippets/csharp/System.Net.Sockets/LingerOption/LingerTime/source.cs
index 4129c1126d3..31a426b3457 100644
--- a/snippets/csharp/System.Net.Sockets/LingerOption/LingerTime/source.cs
+++ b/snippets/csharp/System.Net.Sockets/LingerOption/LingerTime/source.cs
@@ -7,70 +7,70 @@
public class Sync_Send_Receive
{
- public static void SetSocketOptions ()
+ public static void SetSocketOptions()
{
- IPHostEntry lipa = Dns.Resolve ("host.contoso.com");
- IPEndPoint lep = new IPEndPoint (lipa.AddressList[0], 11000);
- Socket s = new Socket (lep.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
-
-//
+ IPHostEntry lipa = Dns.Resolve("host.contoso.com");
+ IPEndPoint lep = new IPEndPoint(lipa.AddressList[0], 11000);
+ Socket s = new Socket(lep.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
+ //
// Send operations will time-out if confirmation
// is not received within 1000 milliseconds.
- s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000);
+ s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000);
+ //
+ //
// The socket will linger for 10 seconds after Socket.Close is called.
- LingerOption lingerOption = new LingerOption (true, 10);
-
- s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption);
+ var lingerOption = new LingerOption(true, 10);
+ s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption);
+ //
-//
- s.Connect (lep);
+ s.Connect(lep);
- byte[] msg = Encoding.ASCII.GetBytes ("This is a test");
+ byte[] msg = Encoding.ASCII.GetBytes("This is a test");
-//
- Console.WriteLine ("This application will timeout if Send does not return within " + Encoding.ASCII.GetString (s.GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4)));
+ //
+ Console.WriteLine("This application will timeout if Send does not return within " + Encoding.ASCII.GetString(s.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4)));
// blocks until send returns
- int i = s.Send (msg);
+ int i = s.Send(msg);
// blocks until read returns
byte[] bytes = new byte[1024];
- s.Receive (bytes);
+ s.Receive(bytes);
- //Display to the screen
- Console.WriteLine (Encoding.ASCII.GetString (bytes));
- s.Shutdown (SocketShutdown.Both);
- Console.WriteLine ("If data remains to be sent, this application will stay open for " + ((LingerOption)s.GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Linger)).LingerTime.ToString ());
- s.Close ();
-//
+ // Display to the screen
+ Console.WriteLine(Encoding.ASCII.GetString(bytes));
+ s.Shutdown(SocketShutdown.Both);
+ Console.WriteLine("If data remains to be sent, this application will stay open for " + ((LingerOption)s.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger)).LingerTime.ToString());
+ s.Close();
+ //
}
- public static void CheckProperties ()
+ public static void CheckProperties()
{
- IPHostEntry lipa = Dns.Resolve ("host.contoso.com");
- IPEndPoint lep = new IPEndPoint (lipa.AddressList[0], 11000);
+ IPHostEntry lipa = Dns.Resolve("host.contoso.com");
+ IPEndPoint lep = new IPEndPoint(lipa.AddressList[0], 11000);
//
- Socket s = new Socket (lep.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
+ Socket s = new Socket(lep.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
- //Using the AddressFamily, SocketType, and ProtocolType properties.
- Console.WriteLine ("I just set the following properties of socket: " + "Address Family = " + s.AddressFamily.ToString () + "\nSocketType = " + s.SocketType.ToString () + "\nProtocolType = " + s.ProtocolType.ToString ());
+ // Using the AddressFamily, SocketType, and ProtocolType properties.
+ Console.WriteLine("I just set the following properties of socket: " + "Address Family = " + s.AddressFamily.ToString() + "\nSocketType = " + s.SocketType.ToString() + "\nProtocolType = " + s.ProtocolType.ToString());
-//
-//
- s.Connect (lep);
+ //
+ //
+ s.Connect(lep);
// Using the RemoteEndPoint property.
- Console.WriteLine ("I am connected to " + IPAddress.Parse (((IPEndPoint)s.RemoteEndPoint).Address.ToString ()) + "on port number " + ((IPEndPoint)s.RemoteEndPoint).Port.ToString ());
+ Console.WriteLine("I am connected to " + IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString()) + "on port number " + ((IPEndPoint)s.RemoteEndPoint).Port.ToString());
// Using the LocalEndPoint property.
- Console.WriteLine ("My local IpAddress is :" + IPAddress.Parse (((IPEndPoint)s.LocalEndPoint).Address.ToString ()) + "I am connected on port number " + ((IPEndPoint)s.LocalEndPoint).Port.ToString ());
+ Console.WriteLine("My local IpAddress is :" + IPAddress.Parse(((IPEndPoint)s.LocalEndPoint).Address.ToString()) + "I am connected on port number " + ((IPEndPoint)s.LocalEndPoint).Port.ToString());
-//
+ //
//
- //Use low level method IOControl to set this socket to blocking mode.
+ // Use low level method IOControl to set this socket to blocking mode.
int code = unchecked((int)0x8004667E);
byte[] inBuf = new byte[4];
@@ -78,17 +78,17 @@ public static void CheckProperties ()
byte[] outBuf = new byte[4];
- s.IOControl (code, inBuf, outBuf);
+ s.IOControl(code, inBuf, outBuf);
- //Check to see that this worked.
+ // Check to see that this worked.
if (s.Blocking)
{
- Console.WriteLine ("Socket was set to Blocking mode successfully");
+ Console.WriteLine("Socket was set to Blocking mode successfully");
}
-//
+ //
}
- public static void Main ()
+ public static void Main()
{
}
}
diff --git a/snippets/visualbasic/VS_Snippets_Remoting/Socket_Socket_Options/VB/source.vb b/snippets/visualbasic/VS_Snippets_Remoting/Socket_Socket_Options/VB/source.vb
index 6b314c2a914..15783fc0b64 100644
--- a/snippets/visualbasic/VS_Snippets_Remoting/Socket_Socket_Options/VB/source.vb
+++ b/snippets/visualbasic/VS_Snippets_Remoting/Socket_Socket_Options/VB/source.vb
@@ -14,16 +14,17 @@ Public Class Sync_Send_Receive
Dim s As New Socket(lep.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
- '
- 'Send operations will time-out if confirmation is
+ '
+ 'Send operations will time-out if confirmation is
' not received within 1000 milliseconds.
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000)
+ '
+ '
' The socket will linger for 10 seconds after Socket.Close is called.
Dim lingerOption As New LingerOption(True, 10)
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption)
-
- '
+ '
s.Connect(lep)
Dim msg As Byte() = Encoding.ASCII.GetBytes("This is a test")
diff --git a/xml/System.Net.Sockets/Socket.xml b/xml/System.Net.Sockets/Socket.xml
index ebe76018bde..ea37eea3649 100644
--- a/xml/System.Net.Sockets/Socket.xml
+++ b/xml/System.Net.Sockets/Socket.xml
@@ -13380,9 +13380,9 @@ The and time-out values.
- :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/Socket_Socket_Options/CPP/source.cpp" id="Snippet1":::
- :::code language="csharp" source="~/snippets/csharp/System.Net.Sockets/LingerOption/LingerTime/source.cs" id="Snippet1":::
- :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/Socket_Socket_Options/VB/source.vb" id="Snippet1":::
+ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/Socket_Socket_Options/CPP/source.cpp" id="Snippet0":::
+ :::code language="csharp" source="~/snippets/csharp/System.Net.Sockets/LingerOption/LingerTime/source.cs" id="Snippet0":::
+ :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/Socket_Socket_Options/VB/source.vb" id="Snippet0":::
]]>