【问题标题】:Grapevine REST server , I could not reach from other PC with IP or host nameGrapevine REST 服务器,我无法通过 IP 或主机名从其他 PC 访问
【发布时间】:2016-01-04 13:15:47
【问题描述】:

我使用的是 VS2012 和 Grapevine 3.0.4,当我使用带有 localhost 的 Grapevine 同一台机器时 主机名,一切正常。 如果我想通过客户端从其他 PC 访问,服务器无法使用主机名 ip 地址或计算机名开始侦听

如果我尝试 server pc set hostname to localhost ,它会开始侦听,但是当从其他具有 IP 或名称服务器的 PC 到达时返回错误请求 400

我的代码或库有问题吗?

我的服务器代码是

public class embeddedHTTP
{
    private RESTServer Server;

    public void ServerStart()
    {
        try
        {
            Server = new RESTServer();
            Server.Port =  GlobalVars.HttpHostPort;
            Server.Host = GlobalVars.HttpHostAdress; // THIS ONLY WORKS FOR LOCALHOST
            Server.MaxThreads = 20;
            Server.Start();

            while (Server.IsListening)
            {
                Thread.Sleep(GlobalVars.HttpHostRespTime);
            }
        }
        catch (Exception ex)
        {
            messenger.logque("embedded HTTP server not started, Error ID : 52", 3, null);
        }
    }

    public void ServerStop()
    {
        Server.Stop();
    }

    public sealed class MyResource : RESTResource
    {    
        //d+$^  [a-zA-Z]+
        [RESTRoute(Method = Grapevine.HttpMethod.GET, PathInfo = @"/")] 
        public void HandleFooRequests(HttpListenerContext context)
        {    
            //String RawuR = context.Request.RawUrl;
            String URL = Convert.ToString(context.Request.Url);
            String ResultXML = brain.HTTPCMD(URL);          
            this.SendTextResponse(context, ResultXML);    
        }    
    }
}

【问题讨论】:

  • 更正:VS2015社区版

标签: c# rest http server grapevine


【解决方案1】:

如果您无法从远程计算机访问服务器,则可能是您运行的防火墙阻止了您正在侦听的端口的入站流量。尝试打开防火墙上的端口,看看是否适合您。

How to Open a Port in the Windows 7 Firewall

此外,您可以使用星号 (*) 作为主机名来监听所有主机。

【讨论】:

    猜你喜欢
    • 2016-04-01
    • 1970-01-01
    • 2017-08-11
    • 1970-01-01
    • 2019-06-15
    • 2016-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多