请教一个问题,那就是我现在做的项目(监控系统)是服务器方面用C++写的来采集数据,而客户端是用asp.net(C#)做的网站,我怎么才能建立客户端与服务器端的通信啊?socket可以吗?给点思路啊....
请大侠们指教....
如果有相关的资料也可以发.cn)里啊也可以加我的QQ(346470752),给我指点一下就好啊!!!
请大侠们指教....
如果有相关的资料也可以发.cn)里啊也可以加我的QQ(346470752),给我指点一下就好啊!!!
解决方案 »
- 关于C#数组的一个很基础的问题求教.
- 诡异问题求解(System.Data.DataRowView”不包含名为“bumenname”的属性)
- C/S自动升级功能——IIS下载扩展名为dll和exe文件的问题
- Test Driven Design
- 急!自定义控件问题!
- access查询中用到“like”DataTable没有返回值
- 那位大大给个.NET CF里C#用的ZIP压缩算法OR例程OR控件?谢谢!!~~
- 从启动后就不能调试
- 如何把access文件连接到winform中去?
- Web页中如何取得DataGrid中某个单元格中的值?
- 存储过程初级问题
- 求救:C#如何使文本框输入数字和小数点,且小数点只有一位呢
我怎么怎么办??是我写的有错吗?
C# Socket 客户端的例子 客户端代码;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;using System.Net;
using System.Net.Sockets;
using System.Threading;namespace ChatToolClient
{
public partial class Form1 : Form
{
Socket clientSocket = null;//客户端套接字
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
try
{
//建立与服务器连接的套接字
IPAddress ip = IPAddress.Parse("172.16.94.134");
IPEndPoint iep = new IPEndPoint(ip, 82);
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
clientSocket.Connect(iep);
textBox2.Text = "连接成功" + "\r\n";
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
} private void send_Click(object sender, EventArgs e)
{ if (textBox1.Text != "")
{
try
{
//发送数据
string message = textBox1.Text;
byte[] sendbytes = System.Text.Encoding.UTF8.GetBytes(message);
int successSendBtyes = clientSocket.Send(sendbytes, sendbytes.Length, SocketFlags.None);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
//将发送的数据显示到对话窗口并使对话窗口的滚动条一直停留在最下方
this.textBox2.Text += "我自己:"+"\r\n"+textBox1.Text + "\r\n";//发完一条消自己息就换行显示
this.textBox2.SelectionStart = this.textBox2.Text.Length;
this.textBox2.ScrollToCaret();
this.textBox1.Text = "";//将发送窗口清空
}
else
{
MessageBox.Show("发送内容不能为空");
}
} private void timer1_Tick(object sender, EventArgs e)
{
byte[] receiveBytes = new byte[1024];
if (clientSocket.Poll(100, SelectMode.SelectRead))
{
int successReceiveBytes = clientSocket.Receive(receiveBytes);
this.textBox2.Text +="服务器:"+"\r\n"+
System.Text.Encoding.UTF8.GetString(receiveBytes, 0, successReceiveBytes) + "\r\n";
this.textBox2.SelectionStart = this.textBox2.Text.Length;//使对话窗口的滚动条一直停留在最下方
this.textBox2.ScrollToCaret();
}
}
}
}C++的服务端 看你用什么开发工具 自己去写吧
我已经连接上了.哈哈,太高兴了.原来是我的C++那边的服务器多线程代码有问题,我改了一下可以了..真是太谢谢了...