remoting 映射外网后登录失败 由于连接方在一段时间后没有正确答复或连接的主机没有反应
用的外网登录,IP地址是外网的:由于连接方在一段时间后没有正确答复或连接的主机没有反应 连接尝试失败 192.168.1.208:9999 显示成了内网的IP地址了,我用外网连的
客户端代码: private void frmLogin_Load(object sender, EventArgs e)
{
ChannelServices.RegisterChannel(new TcpClientChannel(), false);
}
frmmain.db = frmmain.network.GetMainObject(Dns.GetHostName(), Tusername.Text, Md5power.MD5Encrypt(Tuserpwd.Text), "IP" + getIpaddress() + "mac" + GetMacAddressByNetworkInformation() + waiwis); //这句用户验证可以通过,成功
if (frmmain.db != null)
{
DataTable DT = frmmain.db.customerver("version"); //运行到此处就会失败,
if (DT != null)
{
服务端主要代码: //启动服务
private void StartServer()
{
try
{
//创建注册服务器端对象供远程客户端引用
TCPIP = new TcpServerChannel(8208);
ChannelServices.RegisterChannel(TCPIP, false);
System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseTime = TimeSpan.Zero;//设置租用管理器的初始租用时间为无限:
RemotingConfiguration.RegisterWellKnownServiceType(typeof(netbase),
"HT.NETDB", WellKnownObjectMode.SingleCall);
NETServer.ClientConnEvent += new NETServer.EventBase(ClientConnection);
this.启动服务ToolStripMenuItem.Enabled = false;
this.启动服务ToolStripMenuItem.Text = "已启动sql服务";
}
catch (Exception ex)
{
this.启动服务ToolStripMenuItem.Enabled = true;
MessageBox.Show("启动sql服务出现异常!"+ex.ToString(),"提示");
}
}
//客户端连接事件
private void ClientConnection(string username, string IP, string state)
{
listMsg.Items.Add("客户端IP:" + IP + " 用户:" + username + "已" + state);
if (state == "登录")
{
ListViewItem LvItem = new ListViewItem(IP);
LvItem.SubItems.Add(username);
listView1.Items.Add(LvItem);
if (listMsg.Items.Count > 80)
{
listMsg.Items.Clear();
}
if (this.listView1.Items.Count > 80)
{
listView1.Items.Clear();
}
}
else
{
for (int i = 0; i < listView1.Items.Count; i++)
{
if (listView1.Items[i].Text == IP)
{
listView1.Items.RemoveAt(i);
}
}
}
}