new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ) : Socket « System.Net.Sockets « C# / C Sharp by API






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

  


using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

class MainClass
{
  const int echoPort = 7;

  [STAThread]
  static void Main( string[] args )
  {
    Socket s = new Socket( AddressFamily.InterNetwork, 
      SocketType.Stream, 
      ProtocolType.Tcp );
    s.Connect( new IPEndPoint( IPAddress.Loopback, echoPort ) );

    UTF8Encoding enc = new UTF8Encoding();
    s.Send( enc.GetBytes( "test message" ) );
    Byte[] buff = new Byte[ 1024 ];
    s.Receive( buff );
    System.Console.WriteLine( enc.GetString( buff ) );
  }
}

   
    
  








Related examples in the same category

1.Socket.AddressFamily
2.Socket.Bind(IPEndPoint ip)
3.Socket.Blocking
4.Socket.Connect(IPEndPoint ip)
5.Socket.Connected
6.Socket.Listen
7.Socket.LocalEndPoint
8.Socket.ProtocolType
9.Socket.Receive(byte[] data)
10.Socket.ReceiveFrom
11.Socket.Send(String stringValue)
12.Socket.Send(data, data.Length, SocketFlags.None)
13.Socket.SocketType
14.Socket.sentTo