Socket creation

In this chapter you will learn:

  1. Find out AddressFamily, SocketType and ProtocolType for a Socket

Socket AddressFamily, SocketType and ProtocolType

using System;/*j ava  2  s .  com*/
using System.Net;
using System.Net.Sockets;

class MainClass
{
   public static void Main()
   {
      IPAddress ia = IPAddress.Parse("127.0.0.1");
      IPEndPoint ie = new IPEndPoint(ia, 8000);

      Socket test = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

      Console.WriteLine("AddressFamily: {0}",test.AddressFamily);
      Console.WriteLine("SocketType: {0}",test.SocketType);
      Console.WriteLine("ProtocolType: {0}",test.ProtocolType);


      test.Close();
   }
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. How to use SendTo method to send data to server
  2. How to use Send method to send data
Home » C# Tutorial » Network
Cookie
CredentialCache
HostEntry
IPHostEntry
IP address from host name
IPEndPoint from IPAddress
IPEndPoint Port
IPEndPoint properties
IPHostEntry
IP Address Parser
Predefined IP Address
NetworkCredential
Ping
Udp Client
Socket connection
Socket creation
Socket sendTo
TcpClient
TcpListener
UdpClient Receive
UdpClient Sending
Uri
WebClient
Response Headers
WebProxy
WebRequest