I'm trying to get a simple test going with Xamarin and WebSocket4Net but it fails on Open() with "Operation already in progress". Example code below:
using Xamarin.Forms;
using WebSocket4Net;
using System;
using SuperSocket.ClientEngine;
namespace SocketTest
{
public partial class SocketTest : ContentPage
{
private WebSocket websocket;
public SocketTest()
{
InitializeComponent();
}
void Handle_Clicked(object sender, System.EventArgs e)
{
websocket = new WebSocket("ws://echo.websocket.org/");
websocket.Opened += Websocket_Opened;
websocket.Error += Websocket_Error;
websocket.Closed += Websocket_Closed;
websocket.MessageReceived += Websocket_MessageReceived;
websocket.Open();
}
private void Websocket_Error(object sender, ErrorEventArgs e)
{
Console.WriteLine(e.Exception.Message);
}
private void Websocket_MessageReceived(object sender, EventArgs e)
{
Console.WriteLine(e.ToString());
}
private void Websocket_Closed(object sender, EventArgs e)
{
Console.WriteLine(e.ToString());
}
private void Websocket_Opened(object sender, EventArgs e)
{
websocket.Send("Hello World!");
}
}
}
I started with the standard multi-platform project (PCL) and added a button to initiate the connection.
Versions:
0.15.0 WebSocket4Net
0.8.0.13 SuperSocket
The PCL is configured with: .NET Standard Platform = netstandard1.4
I'm fairly new to .NET/Xamarin but have many years of software development behind me.
I've got the same issue with 0.15. Have you tried downgrading to 0.14, and removing SuperSocket?
There's a GitHub issue regarding this problem.
Getting this error when trying to connect in StartReceive()
Here's an excerpt:
Related
HI i wanted to Hide this error box:
i tried serching on internet but did not find usefull results , i am a fresher in coding so any way or any code that can help me ?
This issue is caused from server not acsepting first time but secind time it works great .
it would be great if u provide me easy steps .
MY Currrent code is
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Media_Player
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
{
label2.AutoSize = true;
label1.AutoSize = true;
}
private void button1_Click_1(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = ("http://y0b.net/radiosa.m3u");
MessageBox.Show("Successfuly Selected Radio SA , you will encounter a error , click close and then click play . " , "Thank You" , MessageBoxButtons.OK);
axWindowsMediaPlayer1.Ctlcontrols.play();
label2.Text = "Playing Radio SA";
}
private void button2_Click_1(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
}
private void button3_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.play();
}
private void button4_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = ("http://y0b.net/radiosa2.m3u");
MessageBox.Show("Successfuly Selected Radio SA Clasic , you will encounter a error after this mesage , click close and then click play . ", "Thank You", MessageBoxButtons.OK);
axWindowsMediaPlayer1.Ctlcontrols.play();
label2.Text = "Playing Radio SA CLASSIC ";
}
private void button5_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.pause();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Visible = false;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
radioButton1.Checked = false;
axWindowsMediaPlayer1.Visible = true;
}
private void button6_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = ("http://y0b.net/radiosa3.m3u");
MessageBox.Show("Successfuly Selected Radio SA Dance Department , you will encounter a error after this mesage , click close and then click play . ", "Thank You", MessageBoxButtons.OK);
axWindowsMediaPlayer1.Ctlcontrols.play();
label2.Text = "Playing Radio SA Dance Department";
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
axWindowsMediaPlayer1.settings.volume = trackBar1.Value;
label4.Text = trackBar1.Value.ToString();
}
private void label4_Click(object sender, EventArgs e)
{
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
}
private void progressBar1_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.settings.playCount.ToString();
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.pause();
}
}
}
Try this out. I suppressed the error message by setting enableErrorDialogs to false, then repeatedly asked it to play every 250 ms in a loop, with a ten second time out:
private async void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
axWindowsMediaPlayer1.settings.autoStart = true;
axWindowsMediaPlayer1.settings.enableErrorDialogs = false;
axWindowsMediaPlayer1.URL = "http://y0b.net/radiosa3.m3u";
DateTime stopAt = DateTime.Now.AddSeconds(10);
while (DateTime.Now<stopAt && axWindowsMediaPlayer1.playState!=WMPLib.WMPPlayState.wmppsPlaying)
{
axWindowsMediaPlayer1.Ctlcontrols.play();
await Task.Delay(250);
}
if (axWindowsMediaPlayer1.playState != WMPLib.WMPPlayState.wmppsPlaying)
{
MessageBox.Show("Failed to load stream!");
}
button1.Enabled = true;
}
Music started playing after about two seconds for me. Your mileage may vary...
Note that I added async to the method handler at the top to allow the use of await Task.Delay(250);.
New in the business. Iam creating a windows form Notepad. How do I do the Button Open to open a file and a specific compatible file?
KInd off. I am creating a Notepad with Visual Studio. In the Menu strip, I created a buttion save and another open. De form design its ok, now I need to lear the code c#, to put in the event "Open file" in the notepad that I am creating.
public MeuBloco()
{
InitializeComponent();
}
private void guardarToolStripMenuItem_Click(object sender, EventArgs e)
{
saveFileDialog1.ShowDialog();
}
private void SalvarOK(object sender, CancelEventArgs e)
{
string caminho = saveFileDialog1.FileName;
File.WriteAllText(caminho, txbJanela.Text);
}
private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
}
private void OpenOk(object sender, CancelEventArgs e)
{
}
}
}
// Now I need to code the event to open the file I want.
Is there any possible way to record an audio and upload to a server using xamarin forms.
The best result I got after searching was this
https://github.com/HoussemDellai/UploadFileToServer
The library used in the solution supports only Image and Video.
Thanks in advance
Is there any possible way to record an audio and upload to a server using xamarin forms.
There are many ways realizing this feature. For recording an audio within Xamarin.Forms, you could use Plugin.AudioRecorder to realize. Fore more you could refer the following code.
private AudioRecorderService _recoder;
protected override void OnAppearing()
{
_recoder = new AudioRecorderService
{
StopRecordingOnSilence = true,
StopRecordingAfterTimeout = true,
AudioSilenceTimeout = TimeSpan.FromSeconds(60)
};
_recoder.AudioInputReceived += _recoder_AudioInputReceived;
}
private void _recoder_AudioInputReceived(object sender, string e)
{
// do some stuff
}
private async void Button_Clicked(object sender, EventArgs e)
{
await RecodAudio();
}
private async Task RecodAudio()
{
try
{
if (!_recoder.IsRecording)
{
await _recoder.StartRecording();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
private async void StopButton_Clicked(object sender, EventArgs e)
{
if (_recoder.IsRecording)
{
await _recoder.StopRecording();
}
}
For uploading file, you could use the UploadFileToServer that mentioned in your case. And you will get the audio file path in the AudioInputReceived event args.
private void _recoder_AudioInputReceived(object sender, string e)
{
var path = e;
}
I wonder how I could able to call MMap_MarkerClick from MMap_InfoWindowClick?
private void MMap_InfoWindowClick(object sender, GoogleMap.InfoWindowClickEventArgs e)
{
//call MMap_MarkerClick
}
private void MMap_MarkerClick(object sender, GoogleMap.MarkerClickEventArgs e)
{
ViewModel.MapMarkerSelected(e.Marker.Title);
}
I am trying to achive it, because MMap_InfoWindowClick does not open new ViewModel, but MMap_MarkerClick does. MarkerClick works but InfoWindowClick does not open ViewModel
Okay I have been trying to figure this out if anyone can help me I would be more then grateful.
The code is below im having an issue where it does not execute the .wsf
1. Does anyone see anything that im missing?
2. Am I approaching this correctly?
3.**The script is opening **cmd.exe and connecting to telnet and running commands.
namespace CamSwitch_V1._3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(#"cscript //B //Nologo c:\scripts\Cam1.wsf");
}
}
}
Let me know if you need any more information.