I have been working with WampSharp, i.e the client library provided to connect with autobahn wamp websocket.
I have successfully connected with the Autobahn Wamp Websocket I created in python using a .Net client application using the following code(using WampSharp):
DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory();
channel = channelFactory.CreateChannel(serverAddress);
channel.Open();
here serverAddress is: 127.0.0.1:8000 (i.e. my websocket starts at 8000 port no. of my local machine).
I am using the pubsub mechanism for exchange of data provided by autobahn wamp websocket using following code:
public void Subscribe()
{
ISubject<string> subscribe1 = channel.GetSubject<string>(#"simple/topicSubject1");
IDisposable subject1 = subscribe1.Subscribe(msg => MessageRecieved(msg));
}
public void Publish()
{
ISubject<string> subjectForPublish = channel.GetSubject<string>(#"simple/topicSubject1");
subjectForPublish.OnNext(sd.SerializeObject(DataToPublish));
}
These all processes are done successfully.
The issue I am facing is that I cannot find any handlers to handle the errors and loss of connection as we do in traditional websocket.
In traditional websocket we have handlers like:
webSocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(webSocket_Error);
webSocket.Closed += new EventHandler(webSocket_Closed);
I need to achieve the above functionality using wampsharp.
Thanks in advance.
Try this:
DefaultWampChannelFactory factory = new DefaultWampChannelFactory();
IWampChannel<JToken> channel = factory.CreateChannel("ws://localhost:9090/ws");
IWampClientConnectionMonitor monitor = channel.GetMonitor();
monitor.ConnectionError += ConnectionError;
monitor.ConnectionEstablished += ConnectionEstablished;
monitor.ConnectionLost += ConnectionLost;
await channel.OpenAsync();
Related
First of all, hello everyone as it's my first post.
Getting to the case: I'm trying to send message between two apps - one on computer and the other on Android through Named Pipes and executing the following code ends up with an "The method or operation is not implemented" exception.
The code fragment is an Button Clicked event - the idea is to open a pipe, send through a button text (buttons texts are "Up", "Down", "Left" and "Right) and then close the pipe.
I've tested this and it works as long as the project is a WinForms project using standard System.IO.Pipes.
private void Button_Clicked(object sender, EventArgs e)
{
header.Text = "Pressed: " + (sender as Button).Text;
try
{
using (var pipeClient = new NamedPipeClientStream(SERVERNAME, "testpipe", PipeDirection.Out))
{
header.Text = "Connected with: " + SERVERNAME;
using (var stream = new StreamWriter(pipeClient))
{
pipeClient.Connect();
stream.Write((sender as Button).Text);
}
}
}
catch(Exception exc)
{
Debug.WriteLine(exc.StackTrace);
Debug.WriteLine(exc.Message);
}
}
The line creating an exception is
using (var pipeClient = new NamedPipeClientStream(SERVERNAME, "testpipe", PipeDirection.Out))
I've tested servername (const string) being an IP address, "localhost" or computer name and nothing changes.
Am I doing something wrong or is this a Xamarin error?
Looking in the mono source for NamedPipeClientStream this is only implemented for win32. So it makes sense that you are getting a NotImplementedException.
Not every API that you have available on the desktop is supported on mobile.
Instead of using NamedPipeClientStream you could use TCP Sockets or something more high level as a ASP.NET Core server exposing what you need as a RESTful API or similar and consuming it with HttpClient or any other REST client.
I'am working on simple VoiceChat in C#.
I am using Ozeki framework to make a call with user.
Everything works fine, but I have a problem when I want to make a call after call.
After first call, I have to register my ip again using Ozeki method. But one of my port is still in use. So how can I clear port 5060 after call ?
This is method for register ip:
void Ozeki()
{
softphone = SoftPhoneFactory.CreateSoftPhone(6000, 6200);
microphone = Microphone.GetDefaultDevice();
speaker = Speaker.GetDefaultDevice();
mediaSender = new PhoneCallAudioSender();
mediaReceiver = new PhoneCallAudioReceiver();
connector = new MediaConnector();
var config = new DirectIPPhoneLineConfig(local_ip, 5060);
phoneLine = softphone.CreateDirectIPPhoneLine(config);
phoneLine.RegistrationStateChanged += line_RegStateChanged;
softphone.IncomingCall += softphone_IncomingCall;
softphone.RegisterPhoneLine(phoneLine);
}
So again, how can I 'clear' port 5060?
I'm having an issue with ActiveMQ, I'm trying to connect using MaxReconnectAttemps but its seems to ignore the property. I'm putting an invalid destination so it tries to connect twice but it seems to be trying to connect indefinitely.
Any ideas as to set it up?
Thanks,
IConnectionFactory factory = new ConnectionFactory(("failover://(tcp://localhost:61616)?initialReconnectDelay=2000&maxReconnectAttempts=2"));
using (Connection connection = factory.CreateConnection(username,password) as Connection)
{
connection.ClientId = "ClientId";
using (ISession session = connection.CreateSession())
{
IQueue queue = session.GetQueue(queueName);
var producer = session.CreateProducer(queue);
producer.DeliveryMode = MsgDeliveryMode.Persistent;
ITextMessage request = session.CreateTextMessage("Hello World!");
producer.Send(request);
}
}
Since you are using the .NET client you need to use a prefix on the URI options for the failover transport, so to configure maxReconnectAttempts you need to pass the option like this:
failover:(tcp://localhost:61616)?transport.maxReconnectAttempts=3
It's a good idea to look at the documentation for the client you are using which is here.
I have win service that work with MQ.
But i want that it works using ssl channel and database with public/private keys(for that)
May you explain me how to do it.
P.S. I'm not very good at MQ
now i connect to MQ using this code
MQEnvironment.Hostname = ConfigurationManager.AppSettings["HostnameIN"];
MQEnvironment.Channel = ConfigurationManager.AppSettings["ChannelIN"];
MQEnvironment.Port = int.Parse(ConfigurationManager.AppSettings["PortIN"]);
Environment.SetEnvironmentVariable("MQCCSID", ConfigurationManager.AppSettings["MQCCSID"]);
var mqQueueManagerName = ConfigurationManager.AppSettings["QueueManagerNameIN"];
var mqQueueName = ConfigurationManager.AppSettings["QueueNameIN"];
const int openOptions = MQC.MQOO_BROWSE | MQC.MQOO_INPUT_AS_Q_DEF;
var qMgr = new MQQueueManager(mqQueueManagerName);
var getOptions = new MQGetMessageOptions();
and get all messages using this
using (var mqQueue = qMgr.AccessQueue(mqQueueName, openOptions))
{
try
{
//while (mqQueue.CurrentDepth>0)
while (true)
{
var message = new MQMessage();
//message.Version = 2;
getOptions.Options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_NEXT;
mqQueue.Get(message, getOptions);
mqMessages.Add(message);
}
}
In order to set up MQ to use SSL on the channel you're using, you don't need to make any application changes at all - you simply need to configure the channel you're using on the queue manager to require SSL. The libraries within the client, JVM, and the queue manager will handle establishing that secure connection for you. So in theory all you need to do is make the MQSC/MQ Explorer changes which will configure SSL on the channel.
Recommend you read the following page in the IBM knowledge center. It provides a number of scenarios for various methods of connecting a client securely to the queue manager:
http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.sce.doc/q014220_.htm
I've installed the M4 release of the Apache Qpid Java broker on a Windows box, and started it using the out-of-the-box configuration (via the qpid-server.bat script).
I'm now trying to publish a message to a queue using the RabbitMQ C# client library (version 1.5.3, compiled for .NET 3.0); my code is:
public void PublishMessage(string message)
{
ConnectionFactory factory = new ConnectionFactory();
factory.Parameters.VirtualHost = "...";
IProtocol protocol = Protocols.FromEnvironment();
using (IConnection conn = factory.CreateConnection(protocol, "localhost", 5672))
{
using (IModel ch = conn.CreateModel())
{
string exchange = "...";
string routingKey = "...";
ch.BasicPublish(exchange, routingKey, null, Encoding.UTF8.GetBytes(message));
}
}
}
Basically, I'm unsure what values to use for factory.Parameters.VirtualHost and the strings exchange and routingKey. I've tried various combinations, but nothing seems to work - the closest I've got is seeing the following in the Qpid server log:
2009-03-19 17:11:04,248 WARN [pool-1-thread-1] queue.IncomingMessage (IncomingMessage.java:198) - MESSAGE DISCARDED: No routes for message - Message[(HC:896033 ID:1 Ref:1)]: 1; ref count: 1
which looks as though the Qpid server is receiving the message, but doesn't know what to do with it.
Any advice on what configuration values I need in my client code (bearing in mind I'm using the default Qpid config in virtualhosts.xml) would be much appreciated. More general information on virtual hosts, exchanges, queues and routing keys, and how Qpid links them all together, would also be very useful.
Thank you in advance,
Alan
Just for reference, I managed to get this working in the end. The code below sends a message to the queue test-queue in the test.direct exchange on the localhost virtual host (all part of the default Qpid broker configuration):
public void PublishMessage(string message)
{
ConnectionFactory factory = new ConnectionFactory();
factory.Parameters.VirtualHost = "/localhost";
IProtocol protocol = Protocols.AMQP_0_8_QPID;
using (IConnection conn = factory.CreateConnection(protocol, "localhost", 5672))
{
using (IModel ch = conn.CreateModel())
{
ch.ExchangeDeclare("test.direct", "direct");
ch.QueueDeclare("test-queue");
ch.QueueBind("test-queue", "test.direct", "TEST", false, null);
ch.BasicPublish("test.direct", "TEST", null, Encoding.UTF8.GetBytes(message));
}
}
}