Socket.Send(data, data.Length, SocketFlags.None) : Socket « System.Net.Sockets « C# / C Sharp by API






Socket.Send(data, data.Length, SocketFlags.None)

 
/*
C# Network Programming 
by Richard Blum

Publisher: Sybex 
ISBN: 0782141765
*/
using System;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class SelectTcpClient
{
   public static void Main()
   {
      Socket sock = new Socket(AddressFamily.InterNetwork,
                        SocketType.Stream, ProtocolType.Tcp);
      IPEndPoint iep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
      byte[] data = new byte[1024];
      string stringData;
      int recv;

      sock.Connect(iep);
      Console.WriteLine("Connected to server");
      recv = sock.Receive(data);
      stringData = Encoding.ASCII.GetString(data, 0, recv);
      Console.WriteLine("Received: {0}", stringData);


      while(true)
      {
         stringData = Console.ReadLine();
         if (stringData == "exit")
            break;
         data = Encoding.ASCII.GetBytes(stringData);
         sock.Send(data, data.Length, SocketFlags.None);
         data = new byte[1024];
         recv = sock.Receive(data);
         stringData = Encoding.ASCII.GetString(data, 0, recv);
         Console.WriteLine("Received: {0}", stringData);
      }
      sock.Close();
   }
}

   
  








Related examples in the same category

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