|
- using System;
- using System.IO;
- using System.Net.Sockets;
- using System.Windows.Forms;
- using System.Web;
- namespace TcpSend
- {
- public partial class form1 : Form
- {
- public form1()
- {
- InitializeComponent();
- }
- private void btnSend_Click(object sender, EventArgs e)
- {
- TcpClient tcpClient = new TcpClient(txtHost.Text, Int32.Parse(txtPort.Text));
- NetworkStream ns = tcpClient.GetStream();
- //string addr = HttpContext.Current.Server.MapPath("form1.cs");
- FileStream fs = File.Open(HttpContext.Current.Server.MapPath("form1.cs"), FileMode.Open);
- int data = fs.ReadByte();
- while (data != -1)
- {
- ns.WriteByte((byte)data);
- data = fs.ReadByte();
- }
- fs.Close();
- ns.Close();
- tcpClient.Close();
- }
- }
- }
复制代码 |
|