关于asp.net与delphi应用程序通信的问题,困扰好几天了,请高手解决!
我在我机子上用asp.net做了一个web程序,想用它和其他机子上delphi应用程序通信,web程序是客户端,那个是服务端。用tcpclient,连接没有问题,连接好服务器后 web程序用一个线程执行一个死循环来检查networkstream中的数据,可就是在tbJieshou框中显示不出来,下面是代码 请指教
public partial class _Default : System.Web.UI.Page
{
static TcpClient client;
private static NetworkStream stream;
Thread t ;
protected void Page_Load(object sender, EventArgs e)
{
}
//连接前置机
protected void btnConnect_Click(object sender, EventArgs e)
{
client = new TcpClient(tbIP.Text, Convert.ToInt32(tbPort.Text));
if (!client.Connected)
{
Response.Write("<script language='javascript'>alert('连接前置机失败!')</script>");
}
else
{
stream = client.GetStream();
Response.Write("<script language=javascript>alert('连接成功!')</script>");
}
//IPAddress ip = IPAddress.Parse(tbIP.Text);
//listener = new TcpListener(ip, Convert.ToInt32("2960"));
//listener.Start();
t = new Thread(new ThreadStart(receiveInfo));
t.Start();
}
//发送数据
protected void btnSend_Click(object sender, EventArgs e)
{
string info = tbSend.Text.Trim();
byte[] bytes = System.Text.Encoding.Default.GetBytes(info);
stream.Write(bytes, 0, bytes.Length);
}
//关闭连接
protected void btnUnConnect_Click(object sender, EventArgs e)
{
client.Close();
Response.Write("<script language=javascript>alert('关闭连接!')</script>");
}
//接收数据的函数
private void receiveInfo()
{
int len;
byte[] bytes = new byte[1024];
string msg;
bool flag=true;
while (flag)
{
//bool b = ns.DataAvailable;
//if (b)
//{
len = stream.Read(bytes, 0, bytes.Length);
msg = System.Text.Encoding.Default.GetString(bytes, 0, len);
fuzhi(msg);
}
}
private void fuzhi(string msg)
{
tbJieshou.Text = msg;
//client.Close();
}
}
补充:.NET技术 , ASP.NET