第一步.客户端==》连接服务器并通讯,主要是发送SQL给服务器返回一个DataTable表 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; using System.Net.Sockets; using System.Xml; using System.Xml.Serialization; using System.IO; using System.IO.Compression;
namespace Client { public partial class FormClient : Form { DataTable dt; public FormClient() { InitializeComponent(); }
private void ClientTest(string str) { Socket client; String returnData; byte[] buf = new byte[9991024]; //此处可能有些问题 //IPAddress local = IPAddress.Parse("116.25.83.127"); IPAddress local = IPAddress.Parse("127.0.0.1");//可改为远程IP地址 IPEndPoint iep = new IPEndPoint(local, 6060); try { client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); client.Connect(iep); } catch (SocketException) { Console.WriteLine("无法连接到服务器!"); return ; }
//输入exit,可以断开与服务器的连接 if (str == "") { return; } //发送SQL语句给服务器 client.Send(Encoding.Unicode.GetBytes(str));
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; using System.Net.Sockets; //可以使用套接字 using System.Threading; //可以使用多线程 using System.Data.SqlClient; using System.Xml; using System.Xml.Serialization; using System.IO; using System.IO.Compression;
namespace AppServer { public partial class FormApp : Form { public FormApp() { InitializeComponent(); } private void FormApp_Load(object sender, EventArgs e) { // AppService instance = new AppService(); }