2016-05-03 11 views
1

Ich habe eine SignalR selbst gehostete Anwendung mit Javascript (Jquery) -Clients. Es funktioniert gut lokal, aber ich habe keine Möglichkeit gefunden, von einem Remotecomputer aus eine Verbindung herzustellen. Ich bekomme immer ein Bad Request - Ungültiger Hostname/HTTP-Fehler 400SignalR Self-Host nur localhost Javascript-Clients funktioniert

I Visuelle als Administrator leite ich die Firewall deaktiviert haben, wie Sie im folgenden Code sehen können, habe ich die Server-Seite URL als url = "http://+:8081/"; gesetzt und Ich habe meine IP-Adresse in jquery-Verbindung und den Verweis auf das automatisch generierte signalR Hub-Skript festgelegt.

$(function() { 
 
    // Declare a proxy to reference the hub. 
 
    
 
    $.connection.hub.url = "http://192.168.2.101:8081/signalr"; 
 
    var con = $.connection.myHub; 
 

 
    // Create a function that the hub can call to broadcast messages. 
 
    var Nrobot = 1; 
 
    con.client.broadcastMessage = function (Nrobot, message) { 
 
    }; 
 

 
    $.connection.hub.start({ jsonp: true }).done(function() { 
 
\t \t $('#btn_P06P07').mouseover(function() {con.server.send(Nrobot, "LT");}); 
 
\t \t $('#btn_P01P02').mouseover(function() {con.server.send(Nrobot, "LTI");}); 
 
\t \t $('#btn_P03P04').mouseover(function() {con.server.send(Nrobot, "T") ;}); 
 
\t \t $('#btn_P05P06').mouseover(function() {con.server.send(Nrobot, "TI") ;}); 
 
\t \t $('#btn_P00P03').mouseover(function() {con.server.send(Nrobot, "RT") ;}); 
 
\t \t $('#btn_P02P05').mouseover(function() {con.server.send(Nrobot, "RTI");}); 
 
\t \t //MiddleRow 
 
\t \t $('#btn_P04P07').mouseover(function() {con.server.send(Nrobot, "L");}); 
 
\t \t $('#btn_P12P15').mouseover(function() {con.server.send(Nrobot, "LI");}); 
 
\t \t $('#btn_P10P13').mouseover(function() {con.server.send(Nrobot, "C");}); 
 
\t \t $('#btn_P06P11').mouseover(function() {con.server.send(Nrobot, "R");}); 
 
\t \t $('#btn_P13P14').mouseover(function() {con.server.send(Nrobot, "RI");}); 
 
\t \t //BottomRow 
 
\t \t $('#btn_P11P12').mouseover(function() {con.server.send(Nrobot, "LB");}); 
 
\t \t $('#btn_P07P10').mouseover(function() {con.server.send(Nrobot, "LBI");}); 
 
\t \t $('#btn_P00P01').mouseover(function() {con.server.send(Nrobot, "B");}); 
 
\t \t $('#btn_P02P03').mouseover(function() {con.server.send(Nrobot, "BI");}); 
 
\t \t $('#btn_P04P05').mouseover(function() {con.server.send(Nrobot, "RB");}); 
 
\t \t $('#btn_P14P15').mouseover(function() {con.server.send(Nrobot, "RBI");}); 
 
     $('#btn_oClaw').mousedown(function() { con.server.send(Nrobot, "OClaw"); }); 
 
     $('#btn_cClaw').mousedown(function() { con.server.send(Nrobot, "CClaw"); }); 
 
     $('#btn_rBoom').mousedown(function() { con.server.send(Nrobot, "RBoom"); }); 
 
     $('#btn_lBoom').mousedown(function() { con.server.send(Nrobot, "LBoom"); }); 
 
     $('#btn_lPancam').mousedown(function() { con.server.send(Nrobot, "LPancam"); }); 
 
     $('#btn_rPancam').mousedown(function() { con.server.send(Nrobot, "RPancam"); }); 
 
     $('#btn_rElbow').mousedown(function() { con.server.send(Nrobot, "RElbow"); }); 
 
     $('#btn_lElbow').mousedown(function() { con.server.send(Nrobot, "LElbow"); }); 
 
     $('#btn_lFuture').mousedown(function() { con.server.send(Nrobot, "LFuture"); }); 
 
     $('#btn_rFuture').mousedown(function() { con.server.send(Nrobot, "RFuture"); }); 
 
     $('#btn_oClaw').mouseup(function() { con.server.send(Nrobot, "C"); }); 
 
     $('#btn_cClaw').mouseup(function() { con.server.send(Nrobot, "C"); }); 
 
     $('#btn_rBoom').mouseup(function() { con.server.send(Nrobot, "C"); }); 
 
     $('#btn_lBoom').mouseup(function() { con.server.send(Nrobot, "C"); }); 
 
     $('#btn_lPancam').mouseup(function() { con.server.send(Nrobot, "C"); }); 
 
     $('#btn_rPancam').mouseup(function() { con.server.send(Nrobot, "C"); }); 
 
     $('#btn_rElbow').mouseup(function() { con.server.send(Nrobot, "C"); }); 
 
     $('#btn_lElbow').mouseup(function() { con.server.send(Nrobot, "C"); }); 
 
     $('#btn_lFuture').mouseup(function() { con.server.send(Nrobot, "C"); }); 
 
     $('#btn_rFuture').mouseup(function() { con.server.send(Nrobot, "C"); }); \t \t 
 
     $('#Joystick').mouseleave(function() { con.server.send(Nrobot, "C"); }); 
 
     $(window).mouseleave(function() { con.server.send(Nrobot, "C"); }); \t \t 
 
    }); 
 
    
 
});
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <title></title> 
 
    <link rel="stylesheet" href="robotCSS.css" /> 
 
</head> 
 
<body> 
 
       <table id=Joystick> 
 
        <tr> 
 
         <td> 
 
          <input type="button" class="LTledClass" name="P06P07" id="btn_P06P07" style="height:50px;width:50px" /> 
 
          <input type="button" class="LTledClass" name="P01P02" id="btn_P01P02" style="height:25px;width:25px" /> 
 
         </td> 
 
         <td> 
 
          <input type="button" class="TledClass" name="P03P04" id="btn_P03P04" style="height:50px;width:50px" /> 
 
          <input type="button" class="TledClass" name="P05P06" id="btn_P05P06" style="height:25px;width:50px" /> 
 
         </td> 
 
         <td> 
 
          <input type="button" class="RTledClass" name="P00P03" id="btn_P00P03" style="height:50px;width:50px" /> 
 
          <input type="button" class="RTledClass" name="P02P05" id="btn_P02P05" style="height:25px;width:25px" /> 
 
         </td> 
 
        </tr> 
 
        <tr> 
 
         <td> 
 
          <input type="button" class="LledClass" name="P04P07" id="btn_P04P07" style="height:50px;width:50px" /> 
 
          <input type="button" class="LledClass" name="P12P15" id="btn_P12P15" style="height:50px;width:25px" /> 
 
         </td> 
 
         <td> 
 
          <input type="button" class="ledClass" name="P10P13" id="btn_P10P13" style="height:50px;width:50px" /> 
 
         </td> 
 
         <td> 
 
          <input type="button" class="RledClass" name="P06P11" id="btn_P06P11" style="height:50px;width:50px" /> 
 
          <input type="button" class="RledClass" name="P13P14" id="btn_P13P14" style="height:50px;width:25px" /> 
 
         </td> 
 
        </tr> 
 
        <tr> 
 
         <td> 
 
          <input type="button" class="LBledClass" name="P11P12" id="btn_P11P12" style="height:50px;width:50px" /> 
 
          <input type="button" class="LBledClass" name="P07P10" id="btn_P07P10" style="height:25px;width:25px" /> 
 
         </td> 
 
         <td> 
 
          <input type="button" class="BledClass" name="P00P01" id="btn_P00P01" style="height:50px;width:50px" /> 
 
          <input type="button" class="BledClass" name="P02P03" id="btn_P02P03" style="height:25px;width:50px" /> 
 
         </td> 
 
         <td> 
 
          <input type="button" class="RBledClass" name="P04P05" id="btn_P04P05" style="height:50px;width:50px" /> 
 
          <input type="button" class="RBledClass" name="P14P15" id="btn_P14P15" style="height:25px;width:25px" /> 
 
         </td> 
 
        </tr> 
 
       </table> 
 
       <table id="RightPanel" width="100" height="150" bgcolor="red" border="0"> 
 
        <tr> 
 
         <td> 
 
          <p class="t">Claw</p> 
 
         </td> 
 
         <td> 
 
          <p class="t">Boom</p> 
 
         </td> 
 
        </tr> 
 
        <tr> 
 
         <td> 
 
          <input type="button" class="BTN" value="Open" name="OClaw" id="btn_oClaw" style="height:20px;width:50px" /> 
 
         </td> 
 
         <td> 
 
          <input type="button" class="BTN" value="Raise" name="RBoom" id="btn_rBoom" style="height:20px;width:50px" /> 
 
         </td> 
 
        </tr> 
 
        <tr> 
 
         <td> 
 
          <input type="button" class="BTN" value="Close" name="CClaw" id="btn_cClaw" style="height:20px;width:50px" /> 
 
         </td> 
 
         <td> 
 
          <input type="button" class="BTN" value="Lower" name="LBoom" id="btn_lBoom" style="height:20px;width:50px" /> 
 
         </td> 
 
        </tr> 
 
        <tr> 
 
         <td colspan="2"> 
 
          <p class="t">PanCam</p> 
 
         </td> 
 
        </tr> 
 
        <tr> 
 
         <td> 
 
          <input type="button" class="BTN" value="Left" name="LPancam" id="btn_lPancam" style="height:20px;width:50px" /> 
 
         </td> 
 
         <td> 
 
          <input type="button" class="BTN" value="Right" name="RPancam" id="btn_rPancam" style="height:20px;width:50px" /> 
 
         </td> 
 
        </tr> 
 
        <tr> 
 
         <td> 
 
          <p class="t">Elbow</p> 
 
         </td> 
 
         <td> 
 
          <p class="t">Future</p> 
 
         </td> 
 
        </tr> 
 
        <tr> 
 
         <td> 
 
          <input type="button" class="BTN" value="Raise" name="RElbow" id="btn_rElbow" style="height:20px;width:50px" /> 
 
         </td> 
 
         <td> 
 
          <input type="button" class="BTN" value="Left" name="LFuture" id="btn_lFuture" style="height:20px;width:50px" /> 
 
         </td> 
 
        </tr> 
 
        <tr> 
 
         <td> 
 
          <input type="button" class="BTN" value="Lower" name="LElbow" id="btn_lElbow" style="height:20px;width:50px" /> 
 
         </td> 
 
         <td> 
 
          <input type="button" class="BTN" value="Right" name="RFuture" id="btn_rFuture" style="height:20px;width:50px" /> 
 
         </td> 
 
        </tr> 
 
       </table> 
 

 
    <ul id="Tmess"></ul> 
 
    <!--Script references. --> 
 
    <!--Reference the jQuery library. --> 
 
    <script src="Scripts/jquery-1.6.4.min.js"></script> 
 
    <!--Reference the SignalR library. --> 
 
    <script src="Scripts/jquery.signalR-2.0.3.min.js"></script> 
 
    <!--Reference the autogenerated SignalR hub script. --> 
 
    <script src="http://192.168.2.101:8081/signalr/hubs"></script> 
 
    <!--Add script to update the page and send messages.--> 
 
    <script type="text/javascript" src="Scripts/Centauri.js"></script> 
 
</body> 
 
</html>

static void Main(string[] args) 
    { 
     // This will *ONLY* bind to localhost, if you want to bind to all addresses 
     // use http://*:8080 to bind to all addresses. 
     // See http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx 
     // for more information. 
     string url = "http://+:8081/"; 
     using (WebApp.Start(url)) 
     { 
      Console.WriteLine("Server running on {0}", url); 
      Console.ReadLine(); 
     } 
    } 
} 

class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     //app.UseCors(CorsOptions.AllowAll); 

     app.Map("/signalr", map => 
      { 
       map.UseCors(CorsOptions.AllowAll); 
       var hubConfiguration = new HubConfiguration 
       {      
        EnableJSONP = true      
       };      
       map.RunSignalR(hubConfiguration); 
      }); 

     //app.MapSignalR(); 
     //app.MapSignalR(new HubConfiguration() {EnableJSONP=true}); 

    } 
} 

Nichts funktionierte.

Vielen Dank,

Mit besten Grüßen,

+0

Ich denke, dass das Problem ist, 'String url = "http: // +: 8081 /"; mit (WebApp.Start (url)) '. Ich denke, es hört immer noch nur 'localhost'. – MaKCbIMKo

+0

Hallo MaKCbimKo, Danke für deine schnelle Antwort, wie kann ich das dann ändern? –

+0

Haben Sie versucht, "http: // *: 8081 /" anstelle von "http: // +: 8081 /" zu verwenden? – MaKCbIMKo

Antwort

0

Ok, gefunden

ich die Lösung.

Ich musste die Datei applicationhost.config bearbeiten, aus irgendeinem Grund wurde die Änderung in der URL-Zeichenfolge nicht wirksam.

  <site name="JavascriptClient" id="7"> 
      <application path="/" applicationPool="Clr4IntegratedAppPool"> 
       <virtualDirectory path="/" physicalPath="C:\Users\oloyau\OneDrive\Freelance\1 - Completed\NI USB6501\CentauriBotServer\BotSeverSignalR\C#\JavascriptClient" /> 
      </application> 
      <bindings> 
       <binding protocol="http" bindingInformation="*:31072:**localhost**" /> 
      </bindings> 
     </site> 

Durch den localhost Teil in den Bindungsprotokollparametern zu

Ändern

: 31072:

Es ist kursiv aber von * tatsächlich umgeben ist, weiß ich nicht, wie man sie statt kursiv formatieren, sorry.

Jetzt funktioniert es von anderen Computern in meinem Netzwerk.

Hope this die nächsten in Schwierigkeiten helfen könnte ...

Dank

Verwandte Themen