问题
I am developing WinForm desktop application. I am successfully handshaking with CometD server and then sending change requests to the server. I am sure that requests are successfully received and request command is done by the server and finally expecting that there is a State Changed message by the CometD server. However, there is no message received to me onMessage() method. Does anyone know why? Any suggestions?
public void getCometDAuthenticationRequest(HttpWebRequest request)
{
request = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["MyServer"]);
request.ContentType = "application/json; charset=utf-8";
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(userName + ":" + password));
request.PreAuthenticate = true;
request.Method = "POST";
}
private void connectToCometD()
{
try
{
IClientSessionChannel channel;
BayeuxClient client;
Action<HttpWebRequest> customizeRequest = new Action<HttpWebRequest>(getCometDAuthenticationRequest);
LongPollingTransport transport = new LongPollingTransport(null, customizeRequest);
// Handshake
string url = ConfigurationManager.AppSettings["CometDServer"];
client = new BayeuxClient(url, new List<ClientTransport>() { transport });
client.handshake();
client.waitFor(1000, new List<BayeuxClient.State>() { BayeuxClient.State.CONNECTED });
// Subscription to channels
channel = client.getChannel("/fooChannel");
channel.subscribe(new Listener());
}
catch (Exception e)
{
MessageBox.Show("EXCEPTION ON connectToCometD(): " + e.Message);
return;
}
}
class Listener : IMessageListener
{
public void onMessage(IClientSessionChannel channel, IMessage message)
{
MessageBox.Show("New Message received.. Message:" + message.ToString());
}
}
来源:https://stackoverflow.com/questions/53441782/cannot-receive-cometd-messages-on-net