Operation was cancelled exception when trying to connect signlar with my app?

折月煮酒 提交于 2019-12-12 05:22:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!