server端 部分代码: 传送的是图片 ,但现实不了。
  private void recieve()
        {
            port = Int32.Parse(textBox1.Text);
            IPAddress myIP = IPAddress.Parse("127.0.0.1");
            IPEndPoint localEndPoint = new IPEndPoint(myIP, port);
            listener = new Socket(AddressFamily.InterNetwork,
            SocketType.Stream, ProtocolType.Tcp);
            string data="";
            try
            {
                listener.Bind(localEndPoint);
                listener.Listen(10);
                statusBar1.Text = "开始监听......";
                handler = listener.Accept();                if (handler.Connected)
                {
                    statusBar1.Text = "与客户建立连接";
                }                while (true)
                {
                    byte[] bytes = new byte[1024];
                    int bytesrec = handler.Receive(bytes);
                    data += System.Text.Encoding.ASCII.GetString(bytes, 0, bytesrec);
                    if (data.IndexOf("<EOF>")>-1)
                    {
                        break;
                    }                }
                //MessageBox.Show(data.ToString());
                int lenn = "<EOF>".Length;
                int lenn1 = data.Length - lenn;
                string ss = data.Substring(0, lenn1);
                byte[] by = System.Text.Encoding.ASCII.GetBytes(ss);
                MessageBox.Show((by.Length+"fwq").ToString());
                MemoryStream ms = new MemoryStream(by);
                this.pictureBox1.Image = Image.FromStream(ms);//《==参数无效
                handler.Shutdown(SocketShutdown.Both);
                handler.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            } 
        }
client 端的主要代码:
  private void read()
        {
             int port = 0;
             port = Int32.Parse(this.textBox2.Text.ToString());
             IPAddress myIP = IPAddress.Parse("127.0.0.1");             myIP = IPAddress.Parse(textBox1.Text);
             IPEndPoint remoteEP = new IPEndPoint(myIP, port);
             soc = new Socket(AddressFamily.InterNetwork,
             SocketType.Stream, ProtocolType.Tcp);
             try
             {
                 soc.Connect(remoteEP);                 string file = @"f:\tupian\1.jpg";
                 FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
                 int len =(int) fs.Length;
                 byte[] buf = new byte[len];
                 fs.Read(buf, 0, len);
                 string sr = System.Text.Encoding.ASCII.GetString(buf);
                 //byte[] msg = System.Text.Encoding.ASCII.GetBytes("this is a test<EOF>");
                 string s = sr + "<EOF>";
                 byte[] b = System.Text.Encoding.ASCII.GetBytes(s);
                 //MessageBox.Show("<EOF>".Length.ToString());
                 MessageBox.Show((b.Length + "khd").ToString());
                 int bytesent = soc.Send(b);
                 soc.Shutdown(SocketShutdown.Both);
                 soc.Close();
             }
            catch(ArgumentNullException ane)
             {
                 MessageBox.Show(ane.ToString());             }        }
    }