Grapevine REST服务器,我无法通过其他具有IP或主机名的PC访问

时间:2015-10-07 10:35:41

标签: c# rest http server grapevine

我正在使用VS2012和Grapevine 3.0.4,当我使用与localhost相同的Grapevine机器时 主机名,一切正常。 如果我想从其他PC与客户端联系,服务器无法开始使用主机名IP地址或计算机名称

如果我尝试将服务器pc设置主机名设置为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);    
        }    
    }
}

1 个答案:

答案 0 :(得分:0)

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

How to Open a Port in the Windows 7 Firewall

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

相关问题