ping IP地址的问题,尽管它可以在我的局域网上运行 [英] problem to ping an IP address although it works on my LAN

查看:69
本文介绍了ping IP地址的问题,尽管它可以在我的局域网上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从PC ping IP地址,但是所有软件包都丢失了.我尝试对网站(www.google.com)进行ping操作,没有问题,所有软件包均正确返回.

我已经与要建立连接的地址的管理员进行了交谈,他们说一切正常,并且我的IP地址未被阻止或其他任何原因.
我没有防病毒功能,防火墙已关闭

我尝试在局域网中ping到IP,并且效果很好

请帮助


问题不在于我的代码中,因为我的代码在局域网中可以像ping一样正常工作(在LAN中也可以正常工作),但是在这里,我的代码是TCPServer

I am trying to ping an IP address from my PC but all packages are lost. I tried a ping to a website (www.google.com) and there is no problem, all packages return correctly.

I have spoken to the administrator of the address I''m trying to establish the connection with and they say everything is working OK and that my IP address is not blocked or anything.

I don''t have antivirus and the firewall is off

I try to ping to IP in my LAN and it works fine

help please


the problem isn''t in my code because my code work fine in LAN just like the ping(work fine in LAN too) but here my code TCPServer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;

namespace NetServer
{
  public delegate object ClientConnectHandler(Socket datasocket);
  public delegate void DataReceivedHandler(object obj,byte[] data);
  public delegate void ClientDisconnectHandler(object obj);

  public class TCPServer
  {
    public event ClientConnectHandler WhenClientConnect;
    public event DataReceivedHandler WhenDataReceived;
    public event ClientDisconnectHandler WhenClientDisconnect;
    Socket ConnectionSocket;
    IPEndPoint Endpoint;
    byte[] Data=new byte[10000];
    object obj=new object();
    List OnlineClients = new List();

    public TCPServer()
    {
      ConnectionSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
      Endpoint = new IPEndPoint(IPAddress.Parse(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString()),6666);
    }

    public TCPServer(string ip, int port)
    {
      ConnectionSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
      Endpoint = new IPEndPoint(IPAddress.Parse(ip), port);
    }

    public void Listen()
    {
      ConnectionSocket.Bind(Endpoint);
      ConnectionSocket.Listen(100);
      ConnectionSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
    }

    public void OnClientConnect(IAsyncResult result)
    {
      Socket s = ConnectionSocket.EndAccept(result);
      OnlineClients.Add(s);
      if (WhenClientConnect != null)
        obj = WhenClientConnect(s);
      ConnectionSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
      s.BeginReceive(Data, 0, Data.Length, SocketFlags.None, new AsyncCallback(OnDataReceived), new SSocket { Object=obj , Socket=s});
    }

    public void OnDataReceived(IAsyncResult result)
    {
      SSocket ssocket = (SSocket)result.AsyncState;
      try
      {
        int size = ssocket.Socket.EndReceive(result);
        if (WhenDataReceived != null)
          WhenDataReceived(ssocket.Object, Data.Take(size).ToArray());
        Data = new byte[10000];
        ssocket.Socket.BeginReceive(Data, 0, Data.Length, SocketFlags.None, new AsyncCallback(OnDataReceived), new SSocket { Object = obj, Socket = ssocket.Socket });
      }
      catch(SocketException ex)
      {
        if(ex.ErrorCode == 10054)
        {
          foreach (Socket item in OnlineClients)
            if (ssocket.Socket == item)
              OnlineClients.Remove(item);
          if (WhenClientDisconnect != null)
            WhenClientDisconnect(ssocket.Object);
        }
      }
    }
  
    public void Send(Socket socket,byte[] data)
    {
      if(socket!=null)
        socket.Send(data);
    }
  }

  public class SSocket
  {
    object obj;
    public object Object
    {
      get { return obj; }
      set { obj = value; }
    }
 
    Socket socket;

    public Socket Socket
    {
      get { return socket; }
      set { socket = value; }
    }
  }
}


TCPClient


TCPClient

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Windows.Forms;

namespace NetClientTest
{
  public delegate void DataReceivedHandler(byte[] data);

  public class TCPClient
  {
    byte[] data = new b


[/编辑所有内容]


[/Edit that''s all there is]

推荐答案

根据您的话,您应该在不同网关之间添加路由器.
According to you words, you should add router between different gateway.


非常感谢你们阅读和评论我的问题
我找到了解决方案,并想与您分享
该链接将说明整个问题和解决方案
http://blogs.msdn.com/b/p2p/archive/2007/07/03/ping.aspx [ ^ ]

希望这对某人有帮助
thank you guys very much to read and comment in my question
i found the solution and i want to shared with you
this link will explain the whole problem and the solution
http://blogs.msdn.com/b/p2p/archive/2007/07/03/ping.aspx[^]

hope this help some one


最终我从全球的角度找到了最终的解决方案

当您说要从一台计算机ping到另一台计算机时,为什么拖曳计算机必须具有全局ip地址(世界上唯一)?为什么?

当您从PC请求某个页面的请求时,请首先访问您的ISP(互联网服务提供商)
您的ISP重写该请求,然后将请求发送给服务器(包含页面),然后将响应发送到ISP,然后ISP将其发送回给您.
此过程称为(NAT)
这意味着您可以通过ISP进行互联网导航
这意味着服务器不知道您的ip,他只知道您的ISP ip
这意味着您的IP地址是本地的

但是问题仍然存在,我该如何建立P2P连接?
我仍在寻找答案,但您可以阅读有关PNRP的更多信息
finally i found the ultimate solution from a global perspective

when you say you want to ping from one computer to another the tow computer must have a global ip address (unique in the world) why?

when you request some page from your pc that request go first to your ISP (Internet Service Provider)
your ISP rewrite that request and send it for you the server (that contain the page) send response to your ISP Then the ISP send it back to you.
this process called (NAT)
that''s mean you navigate throw the internet by your ISP
that''s mean the server don''t know your ip he just know your ISP ip
that''s mean your ip is local

but the question is still exist how can i make a P2P connection?
i am still working on the answer but you can read more about PNRP


这篇关于ping IP地址的问题,尽管它可以在我的局域网上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆