I am using jabber-net as my xmpp chat client with C# application. Chat server I am using is apache vysper 0.7
I created chat client using following code.
private void ChatOne_Load(object sender, EventArgs e)
{
JID jid = new JID("user1#test.com");
this.chatOneJabberClient.User = jid.User;
this.chatOneJabberClient.Server = jid.Server;
this.chatOneJabberClient.Password = "password1";
//this.chatOneJabberClient.AutoPresence = false;
//this.chatOneJabberClient.AutoRoster = false;
//this.chatOneJabberClient.AutoReconnect = -1;
this.chatOneJabberClient.OnAuthenticate += chatOneJabberClient_OnAuthenticate;
this.chatOneJabberClient.OnError += chatOneJabberClient_OnError;
this.chatOneJabberClient.OnReadText += chatOneJabberClient_OnReadText;
this.chatOneJabberClient.OnWriteText += chatOneJabberClient_OnWriteText;
this.chatOneJabberClient.Connect();
this.chatOneJabberClient.Login();
//done.WaitOne();
}
But what i understand from docs give over here is once the client is connected and login method is called it will automatically call the handler for OnAuthenticate.
When I try to send the message
private void button1_Click(object sender, EventArgs e)
{
this.chatOneJabberClient.Message("user2#test.com", this.textBox2.Text);
this.textBox2.Clear();
}
It throws and invalid operation exception. User must be authenticated first.
Do let me know if you want any other information.
When jabberClient starts it calls the OnWriteText methoda handler and I can see following thing in my chat box:
Send: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" id="cb7f31d2" xmlns="jabber:client" to="test.com" version="1.0">
Do let me know if you need any further info.
I figured out the issue.
The problem was with my chat server. I am using apache vysper. I was trying to use web-socket endpoint. In current version of vysper there is not much active development on web-socket. I changed it to TcpEndPoint and its all good. :)
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 trying to transfer a file to my iphone using 32feet bluetooth, but cannot seem to get past the ObexWebResponse.
I have read many post on this but none of the solutions seem to work for me.
The Error i get is
// Connect failed
// The requested address is not valid in its context "address:Guid"
private BluetoothClient _bluetoothClient;
private BluetoothComponent _bluetoothComponent;
private List<BluetoothDeviceInfo> _inRangeBluetoothDevices;
private BluetoothDeviceInfo _hlkBoardDevice;
private EventHandler<BluetoothWin32AuthenticationEventArgs> _bluetoothAuthenticatorHandler;
private BluetoothWin32Authentication _bluetoothAuthenticator;
public BTooth() {
_bluetoothClient = new BluetoothClient();
_bluetoothComponent = new BluetoothComponent(_bluetoothClient);
_inRangeBluetoothDevices = new List<BluetoothDeviceInfo>();
_bluetoothAuthenticatorHandler = new EventHandler<BluetoothWin32AuthenticationEventArgs>(_bluetoothAutenticator_handlePairingRequest);
_bluetoothAuthenticator = new BluetoothWin32Authentication(_bluetoothAuthenticatorHandler);
_bluetoothComponent.DiscoverDevicesProgress += _bluetoothComponent_DiscoverDevicesProgress;
_bluetoothComponent.DiscoverDevicesComplete += _bluetoothComponent_DiscoverDevicesComplete;
ConnectAsync();
}
public void ConnectAsync() {
_inRangeBluetoothDevices.Clear();
_hlkBoardDevice = null;
_bluetoothComponent.DiscoverDevicesAsync(255, true, true, true, false, null);
}
private void PairWithBoard() {
Console.WriteLine("Pairing...");
bool pairResult = BluetoothSecurity.PairRequest(_hlkBoardDevice.DeviceAddress, null);
if (pairResult) {
Console.WriteLine("Success");
Console.WriteLine($"Authenticated equals {_hlkBoardDevice.Authenticated}");
} else {
Console.WriteLine("Fail"); // Instantly fails
}
}
private void _bluetoothComponent_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e) { _inRangeBluetoothDevices.AddRange(e.Devices); }
private void _bluetoothComponent_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e) {
for (int i = 0; i < _inRangeBluetoothDevices.Count; ++i) {
if (_inRangeBluetoothDevices[i].DeviceName == "Uranus") {
_hlkBoardDevice = _inRangeBluetoothDevices[i];
PairWithBoard();
TransferFile();
return;
}
}
// no devices found
}
private void _bluetoothAutenticator_handlePairingRequest(object sender, BluetoothWin32AuthenticationEventArgs e) {
e.Confirm = true; // Never reach this line
}
// not working
// transfers a file to the phone
public void TransferFile() {
string file = "E:\\test.txt",
filename = System.IO.Path.GetFileName(file);
string deviceAddr = _hlkBoardDevice.DeviceAddress.ToString();
BluetoothAddress addr = BluetoothAddress.Parse(deviceAddr);
_bluetoothClient.Connect(BluetoothAddress.Parse(deviceAddr), BluetoothService.SerialPort);
Uri u = new Uri($"obex://{deviceAddr}/{file}");
ObexWebRequest owr = new ObexWebRequest(u);
owr.ReadFile(file);
// error:
// Connect failed
// The requested address is not valid in its context ...
var response = (ObexWebResponse)owr.GetResponse();
Console.WriteLine("Response Code: {0} (0x{0:X})", response.StatusCode);
response.Close();
}
The pairing and authentication works just fine, and I can get the BluetoothService.Handsfree to make a call for me but the transferring of the file fails. Not knowing what the actual error is, I tried almost every service available with no luck.
Can you help me figure out what is going on? This is my first attempt working with Bluetooth services so I still have a ton to learn.
Is it possible to transfer a file from iPhone to Windows desktop via Bluetooth?
However, in case you need to transfer media files (images, videos, etc) from Android device, you can use ObexListener class provided by 32Feet library for this purpose, and then you can simply call _obexListener.GetContext() method that will block and wait for incoming connections.
Once a new connection is received, you can save the received file to local storage, as shown in the below example:
ObexListener _listener = new ObexListener();
_listener.Start();
// This method will block and wait for incoming connections
ObexListenerContext _context = _listener.GetContext();
// Once new connection is received, you can save the file to local storage
_context.Request.WriteFile(#"c:\sample.jpg");
NOTE: When working with OBEX on Windows, make sure to disable the "Bluetooth OBEX Service" Windows service, in order not to let it handle the incoming OBEX requests instead of the desired application.
I walked away from this for a while. and started Trying to use xamiren but then had to create a virtual Mac so that I could have the apple store to just load software on my phone. From there xamerin 'should' work well but its another field and tons more to firgure out.
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();
I never used fiddler core before. But after first time using it into my application, a weird problem is happening. Whenever my application is running web browsers are working fine. But other time those all showing error page. I know I did something wrong with fiddler core. I am sending my codes here. Codes are working perfectly. But there is something into my code so that I getting this problem. Please see the code and let me know what am I doing wrong.
static bool bUpdateTitle = true;
static Proxy oSecureEndpoint;
static string sSecureEndpointHostname = "localhost";
static int iSecureEndpointPort = 1106;
private void button1_Click(object senderr, EventArgs e)
{
List<Fiddler.Session> oAllSessions = new List<Fiddler.Session>();
Fiddler.FiddlerApplication.OnNotification += delegate(object sender, NotificationEventArgs oNEA) { MessageBox.Show("** NotifyUser: " + oNEA.NotifyString); };
Fiddler.FiddlerApplication.BeforeRequest += delegate(Fiddler.Session oS)
{
oS.bBufferResponse = false;
Monitor.Enter(oAllSessions);
oAllSessions.Add(oS);
Monitor.Exit(oAllSessions);
if (oS.hostname=="localhost")
{
oS.utilCreateResponseAndBypassServer();
oS.oResponse.headers.HTTPResponseStatus = "200 Ok";
oS.oResponse["Content-Type"] = "text/html; charset=UTF-8";
oS.oResponse["Cache-Control"] = "private, max-age=0";
oS.utilSetResponseBody("<html><body><font size=10>Restricted</font></body></html>");
}
};
Fiddler.CONFIG.IgnoreServerCertErrors = false;
FiddlerApplication.Prefs.SetBoolPref("fiddler.network.streaming.abortifclientaborts", true);
FiddlerCoreStartupFlags oFCSF = FiddlerCoreStartupFlags.Default;
Fiddler.FiddlerApplication.Startup(0, oFCSF);
oSecureEndpoint = FiddlerApplication.CreateProxyEndpoint(iSecureEndpointPort, true, sSecureEndpointHostname);
}
public static void DoQuit()
{
if (null != oSecureEndpoint) oSecureEndpoint.Dispose();
Fiddler.FiddlerApplication.Shutdown();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DoQuit();
}
As mentioned in the response to your same message left in the Fiddler discussion group, this means that you ran your program at least once without properly calling Shutdown() (e.g. because it crashed). Clear the incorrect proxy settings from Tools > Internet Options > Connections > LAN Settings when your program isn't running.
I'm creating a windows desktop sharing app and have everything working except the virtual channels for sending chat messages. I can send messages from the host to the Viewer but not vice versa. The Viewer is using the ActiveX RDPViewer. The problem is I can't get the OnChannelDataRecieved event to fire on the host. I know some people have had trouble with this before but any help would be appreciated.
Here is some snippets that might help.
Viewer
RDPCOMAPILib.IRDPSRAPIVirtualChannel chan;
chan = rdpViewer.VirtualChannelManager.CreateVirtualChannel(name, RDPCOMAPILib.CHANNEL_PRIORITY.CHANNEL_PRIORITY_HI, 0);
Then when sending i call
chan.SendData(message, (int)RDPCOMAPILib.RDPENCOMAPI_CONSTANTS.CONST_ATTENDEE_ID_HOST, 0);
Host
chan = rdp.VirtualChannelManager.CreateVirtualChannel(name, RDPCOMAPILib.CHANNEL_PRIORITY.CHANNEL_PRIORITY_HI, 0);
foreach(IRDPSRAPIAttendee attendee in rdp.Attendees)
this.vc.SetAccess(attendee.Id, RDPCOMAPILib.CHANNEL_ACCESS_ENUM.CHANNEL_ACCESS_ENUM_SENDRECEIVE);
Then I call this to send data
chan.SendData(message, (int)RDPCOMAPILib.RDPENCOMAPI_CONSTANTS.CONST_ATTENDEE_ID_EVERYONE, 0);
Here's the technique that I use that works well for my needs:
//----------------------------------------------------------------------------------------
// On the server/host, create a new session
//----------------------------------------------------------------------------------------
RDPSession session = new RDPSession();
// Then create a virtual channel
IRDPSRAPIVirtualChannel virtualChannel1 = session.VirtualChannelManager.CreateVirtualChannel("foo", CHANNEL_PRIORITY.CHANNEL_PRIORITY_HI, (uint)CHANNEL_FLAGS.CHANNEL_FLAGS_LEGACY);
// Now open the session
session.Open()
// And connect to the received event
session.OnChannelDataReceived += new _IRDPSessionEvents_OnChannelDataReceivedEventHandler(OnChannelDataReceived);
private void OnChannelDataReceived(object pChannel, int lAttendeeId, string bstrData) {
Debug.WriteLine("Server::OnChannelDataReceived" + bstrData.Trim());
}
//----------------------------------------------------------------------------------------
// On the Client/Viewer side.
//----------------------------------------------------------------------------------------
// AxRDPViewer is the RDPViewer control on your form. Connect using the appropriate criteria.
AxRDPViewer.Connect(strInvitation, strName, strPassword);
// "Bind" the virtual channel by creating one using the same name as the one created on
// the server side.
IRDPSRAPIVirtualChannel virtualChannel1 = RDPViewer.VirtualChannelManager.CreateVirtualChannel("foo", CHANNEL_PRIORITY.CHANNEL_PRIORITY_HI, (uint)CHANNEL_FLAGS.CHANNEL_FLAGS_LEGACY);
// Hook the data received event
RDPViewer.OnChannelDataReceived += new AxRDPCOMAPILib._IRDPSessionEvents_OnChannelDataReceivedEventHandler(RDPViewer_OnChannelDataReceived);
private void RDPViewer_OnChannelDataReceived(object sender, AxRDPCOMAPILib._IRDPSessionEvents_OnChannelDataReceivedEvent e) {
Debug.WriteLine("Client::OnChannelDataReceived:" + e.bstrData.Trim());
}
//----------------------------------------------------------------------------------------
// Sending data
//----------------------------------------------------------------------------------------
// Now, on both the server and client side, you can send data like this:
virtualChannel1.SendData("yippie!", (int)RDPENCOMAPI_CONSTANTS.CONST_ATTENDEE_ID_EVERYONE, (uint)CHANNEL_FLAGS.CHANNEL_FLAGS_LEGACY);
I hope that helps. I actually struggled with this for awhile, only to end up realizing that I was launching a modal dialog over my form that was responsible for hooking the session events. So don't do that. ;)
Using RDPENCOMAPI_CONSTANTS.CONST_ATTENDEE_ID_EVERYONE didn't work for me.
The only way I solved that issue was to use SendData iterating over session's attendees.
foreach (IRDPSRAPIAttendee a in _ctx.activeSession.Attendees)
virtualChannel.SendData(msg, a.Id, Convert.ToUInt32(CHANNEL_FLAGS.CHANNEL_FLAGS_LEGACY));
While this solves the Host-to-Viewer communication I still can't receive any message from a connected viewer, registed on the same virtual channel and using RDPENCOMAPI_CONSTANTS.CONST_ATTENDEE_ID_HOST constant.
What I've done server-side is to create a new RDPSession and a virtual channel
activeSession = new RDPSession();
virtualChannel = activeSession.VirtualChannelManager.CreateVirtualChannel("myproto", CHANNEL_PRIORITY.CHANNEL_PRIORITY_HI, (uint)CHANNEL_FLAGS.CHANNEL_FLAGS_LEGACY);
create a new handler for OnChannelDataReceived event and start the RDP session.
activeSession.OnChannelDataReceived += new _IRDPSessionEvents_OnChannelDataReceivedEventHandler(OnChannelDataReceived);
activeSession.Open();
Event handler looks like this:
private void OnChannelDataReceived(object pChannel, int lAttendeeId, string bstrData) {
switch(bstrData)
{
/* Handle commands here */
case "mycmd":
/* Process command and reply using SendData */
break;
}
}
Viewer runs on Windows 10 while server runs on Windows 7 and they both uses RDPCOMAPI generated from Windows 7 rdpcomen.dll using tlbimp.exe tool.