问题
Am trying to connect my application sample signal r application. I works well and established connection when using javascript but while using android am getting java.lang.InterruptedException: Operation was cancelled exception don't know where am making mistake let me post my code this is the simple hub connection class:
namespace ChatRoomApplication
{
public class ChatHub : Hub
{
public void Send(string name, string message)
{
Clients.All.sendMessages(name, message);
}
}
}
This is my client android code:
public class MainActivity extends AppCompatActivity {
private final Context mContext = this;
private SignalRService mService;
private boolean mBound = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
startSignalR();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
private void startSignalR() {
Platform.loadPlatformComponent(new AndroidPlatformComponent());
Toast.makeText(this, "Service Start", Toast.LENGTH_LONG).show();
String server = "http://172.16.6.106:8080/ChatRoomApplication/";
HubConnection connection = new HubConnection(server);
HubProxy proxy = connection.createHubProxy("ChatHub");
SignalRFuture<Void> awaitConnection = connection.start();
try {
awaitConnection.get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
proxy.invoke("Send", "Yoge","Yoges");
}
Can someone help me am getting confused why am getting this exception!!
来源:https://stackoverflow.com/questions/40231733/operation-was-cancelled-exception-when-trying-to-connect-signlar-with-my-app