是这样!~我是想采用REMOTING的HTTP连接来做一个即时通讯的小软件!~我是想让客户端连接到服务器~然后服务器获得它的IP地址~然后也获得它要联系的人的IP地址!~最后让它俩点对点通信!~
由于我对REMOTING还不怎么了解!~所以我实际上是这么做的我先建立了个叫CLASS1的类!这里面处理从客户端传来的客户端信息
public class Class1 : System.MarshalByRefObject
{
string strXinxi;
public string addmsg(string CustID,string msg)
{
messages.Add(msg); strXinxi = "信息来自:" + CustID + ",消息为:" + msg; MessageBox.Show(strXinxi);
return strXinxi;
}
}这样我在服务器端用的是个WINDOWS窗体!~里面有个listBox控件!~ private void button1_Click(object sender, System.EventArgs e)
{
HttpChannel channel = new HttpChannel(9932); // 建立HTTP连接管道服务 ChannelServices.RegisterChannel(channel); // 向管道服务注册管道
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Class1),"Class1",WellKnownObjectMode.SingleCall); statusBar1.Text = "服务器状态:已启动"; }在客户端我就是把把连接的服务器地址给写进去!然后把客户信息发给CLASS1 private void button1_Click(object sender, System.EventArgs e)
{
port = int.Parse(textBox3.Text);//客户端连接的端口 ChannelServices.RegisterChannel(new HttpChannel(port)); clianjie = (Class1)Activator.GetObject(typeof(tongyongleiku.Class1),"http://192.168.1.9:9932/Class1"); if(clianjie == null)
{
statusBar1.Text = "状态:无法连接到服务器";
}
else
{
statusBar1.Text = "状态:已连接服务器";
string ComputerName = Dns.GetHostName(); IPHostEntry myHost = new IPHostEntry();
myHost = Dns.Resolve(ComputerName);
string strCIP = myHost.AddressList[0].ToString(); } }这样CLASS1就能收到客户端的信息了!~
可我想在服务器端的LISTBOX里呈现客户端信息!并一直监听它的状态!
可这个我就不知道怎么写了!!!~
1。我怎么把组件CLASS1里返回的值在呈现到LISTBOX里啊?!?!
谢谢大家了!
2。还有就是我思路上有啥问题!?具体这样写行不行也请大家指教
由于我对REMOTING还不怎么了解!~所以我实际上是这么做的我先建立了个叫CLASS1的类!这里面处理从客户端传来的客户端信息
public class Class1 : System.MarshalByRefObject
{
string strXinxi;
public string addmsg(string CustID,string msg)
{
messages.Add(msg); strXinxi = "信息来自:" + CustID + ",消息为:" + msg; MessageBox.Show(strXinxi);
return strXinxi;
}
}这样我在服务器端用的是个WINDOWS窗体!~里面有个listBox控件!~ private void button1_Click(object sender, System.EventArgs e)
{
HttpChannel channel = new HttpChannel(9932); // 建立HTTP连接管道服务 ChannelServices.RegisterChannel(channel); // 向管道服务注册管道
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Class1),"Class1",WellKnownObjectMode.SingleCall); statusBar1.Text = "服务器状态:已启动"; }在客户端我就是把把连接的服务器地址给写进去!然后把客户信息发给CLASS1 private void button1_Click(object sender, System.EventArgs e)
{
port = int.Parse(textBox3.Text);//客户端连接的端口 ChannelServices.RegisterChannel(new HttpChannel(port)); clianjie = (Class1)Activator.GetObject(typeof(tongyongleiku.Class1),"http://192.168.1.9:9932/Class1"); if(clianjie == null)
{
statusBar1.Text = "状态:无法连接到服务器";
}
else
{
statusBar1.Text = "状态:已连接服务器";
string ComputerName = Dns.GetHostName(); IPHostEntry myHost = new IPHostEntry();
myHost = Dns.Resolve(ComputerName);
string strCIP = myHost.AddressList[0].ToString(); } }这样CLASS1就能收到客户端的信息了!~
可我想在服务器端的LISTBOX里呈现客户端信息!并一直监听它的状态!
可这个我就不知道怎么写了!!!~
1。我怎么把组件CLASS1里返回的值在呈现到LISTBOX里啊?!?!
谢谢大家了!
2。还有就是我思路上有啥问题!?具体这样写行不行也请大家指教
解决方案 »
- vs生成的安装包,安装时出现的问题
- 求助!vs2010 express 如何 找到 source control 以便连接 代码版本管理软件
- sqlcommand.ExecuteNonQuery(), 多条语句超时问题..
- C#中有关事件参数object sender, System.EventArgs e没有使用的问题
- 请问怎么做帮助文档啊?大家给个提示
- 如何把数据库里的数据导入DropDownList中!
- 在datagrid中实现点击单元格并配合ctrl来多选
- 没有安装ACCESS的机器上可以运行操作MDB数据库的.NET程序吗?
- 关于Replace替换为什么没有用
- 在C#里面大量执行 sql 的insert语句。
- DevExpress控件包2.0中的DateEdit控件问题。
- try catch 好稀奇的问题
我这样做的话局域网跟公网能通信么?!
还是要UDP打洞?REMOTING能实现么?