尝试连接时出错:
ReactNativeJS: [12:52:08 GMT+0000 (GMT)] SignalR: Client subscribed to hub 'chathub'.
ReactNativeJS: [12:52:08 GMT+0000 (GMT)] SignalR: Negotiating with 'http://10.0.2.2:50069/chathub/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D'.
ReactNativeJS: 'SignalR error: Error during negotiation request.', ''
ReactNativeJS: Failed
ReactNativeJS: [12:52:08 GMT+0000 (GMT)] SignalR: Stopping connection.
服务器:
public class ChatHub : Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
}
在启动.cs(省略未绑定的条目)
public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, DataContext context)
{
// global cors policy
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
app.UseMvc();
app.UseSignalR(routes =>
{
routes.MapHub<ChatHub>("/chatHub");
});
}
本地反应:
import signalr from 'react-native-signalr';
export default class Settings extends Component{
componentDidMount() {
//This is the server under /example/server published on azure.
const connection = signalr.hubConnection('http://10.0.2.2:50069/chathub');
connection.logging = true;
const proxy = connection.createHubProxy('chatHub');
//receives broadcast messages from a hub function, called "helloApp"
proxy.on('SendMessage', (argOne, argTwo, argThree, argFour) => {
console.log('message-from-server', argOne, argTwo, argThree, argFour);
//Here I could response by calling something else on the server...
});
// atempt connection, and handle errors
connection.start().done(() => {
console.log('Now connected, connection ID=' + connection.id);
proxy.invoke('sendMessage', 'Hello Server, how are you?', 'ffff')
.done((directResponse) => {
console.log('direct-response-from-server', directResponse);
}).fail(() => {
console.warn('Something went wrong when calling server, it might not be up and running?')
});
}).fail(() => {
console.log('Failed');
});
//connection-handling
connection.connectionSlow(() => {
console.log('We are currently experiencing difficulties with the connection.')
});
connection.error((error) => {
const errorMessage = error.message;
let detailedError = '';
if (error.source && error.source._response) {
detailedError = error.source._response;
}
if (detailedError === 'An SSL error has occurred and a secure connection to the server cannot be made.') {
console.log('When using react-native-signalr on ios with http remember to enable http in App Transport Security https://github.com/olofd/react-native-signalr/issues/14')
}
console.debug('SignalR error: ' + errorMessage, detailedError)
});
}
render(){
return(
<View style={{flex: 1}}>
</View>
)
}
}
我做了一切应该做的事,但我不想做任何联系。我在用10个窗户。
也许我忘了密码里的东西?