
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Networking in C#
The .NET Framework has a layered, extensible, and managed implementation of networking services. You can easily integrate them into your applications. Use the System.Net; namespace.
Let us see how to acess the Uri class:.In C#, it provides object representation of a uniform resource identifier (URI) −
Uri uri = new Uri("http://www.example.com/"); WebRequest w = WebRequest.Create(uri);
Let us now see the System.Net class. This is used to encorypt connections using using the Secure Socket Layer (SSL). If the URI begins with "https:", SSL is used; if the URI begins with "http:", an unencrypted connection is used.
The following is an example. For SSL with FTP, set the EnableSsl property to true before calling the GetResponse() method.
String uri = "https://www.example.com/"; WebRequest w = WebRequest.Create(uri); String uriServer = "ftp://ftp.example.com/new.txt" FtpWebRequest r = (FtpWebRequest)WebRequest.Create(uriServer); r.EnableSsl = true; r.Method = WebRequestMethods.Ftp.DeleteFile;
The following is an example showing the usage of System.Net namespace and using the Dns.GetHostEntry, Dns.GetHostName methods and IPHostEntry property AddressList −
Example
using System; using System.Net; class Program { static void Main() { String hostName = string.Empty; hostName = Dns.GetHostName(); Console.WriteLine("Hostname: "+hostName); IPHostEntry myIP = Dns.GetHostEntry(hostName); IPAddress[] address = myIP.AddressList; for (int i = 0; i < address.Length; i++) { Console.WriteLine("IP Address {1} : ",address[i].ToString()); } Console.ReadLine(); } }
- Related Articles
- What is Piggybacking in Networking?
- OSI Model in Computer Networking
- TCP/IP in Computer Networking
- Future of Networking
- Unknown Facts Of Networking
- Low-level networking interface in Python (socket)
- Metropolitan Area Network (MAN) in Computer Networking
- What is a Networking in information security?
- Role of Cloud Computing In Social Networking
- Difference between Hardware and Networking
- What are the SONET/SDH standards in networking?
- 2-tier and 3-tier Architecture in Networking
- Launch a career in IT Hardware and Networking
- Decoding MAN: Understanding its Role in Computer Networking
- What is Software Defined Networking (SDN)?
