i am trying to send audio to a AXIS M1054 Network Camera. When i start my application, it after sending 6 packets to the camera shows an error:"An established connection was aborted by the software in your host machine"
here's the code
namespace sound_stream
{
public partial class Form1 : Form
{
public static IWaveIn waveSource = null;
public Socket cameraAudioSocket = null;
public IPEndPoint remoteEndPoint = null;
public string camera_address = "192.168.1.22";
public int camera_port = 81;
public byte[] allData = null;
private MemoryStream mstream = new MemoryStream();
public Form1()
{
InitializeComponent();
}
private void start_Click(object sender, EventArgs e)
{
try
{
start.Enabled = false;
stop.Enabled = true;
waveSource = new WaveIn();
waveSource.WaveFormat = new WaveFormat(8000, 1);
CameraSetup();
if (cameraAudioSocket == null)
{
cameraAudioSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse(camera_address), camera_port);
cameraAudioSocket.Connect(remoteEndPoint);
}
waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
waveSource.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);
waveSource.StartRecording();
}
catch (Exception ex)
{
MessageBox.Show(null, "Error: " + ex.ToString(), "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
void waveSource_DataAvailable(object sender, WaveInEventArgs e)
{
try
{
byte[] encoded = G711.Encode_uLaw(e.Buffer, 0, e.BytesRecorded);
cameraAudioSocket.Send(encode,encoded.Length, SocketFlags.None);
}
catch (SocketException er)
{
status.Text += er.Message;
}
}
void CameraSetup()
{
try
{
cameraAudioSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse(camera_address), camera_port);
cameraAudioSocket.Connect(remoteEndPoint);
string httpPostString =
"POST /axis-cgi/audio/transmit.cgi HTTP/1.0" + Environment.NewLine
+ "Content-Type: audio/basic" + Environment.NewLine
+ "Content-Length: 9999999" + Environment.NewLine
+ "Connection: Keep-Alive" + Environment.NewLine
+ "Cache-Control: no-cache" + Environment.NewLine
+ "Authorization: root pass" + Environment.NewLine + Environment.NewLine;
byte[] httpPostData = Encoding.Unicode.GetBytes(httpPostString);
if (cameraAudioSocket.Send(httpPostData) == -1)
status.Text += "Error sending initial packet";
}
catch (SocketException err)
{
status.Text += err.Message;
}
}
void waveSource_RecordingStopped(object sender, EventArgs e)
{
if (waveSource != null)
{
waveSource.Dispose();
waveSource = null;
}
}
private void stop_Click_1(object sender, EventArgs e)
{
stop.Enabled = false;
waveSource.StopRecording();
start.Enabled = true;
cameraAudioSocket.Close();
}
private void clear_Click(object sender, EventArgs e)
{
status.Text = null;
}
}
}
Exception details:
System.Net.Sockets.SocketException was caught
Message="An established connection was aborted by the software in your host machine"
Source="System"
ErrorCode=10053
NativeErrorCode=10053
StackTrace:
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 size, SocketFlags socketFlags)
at sound_stream.Form1.waveSource_DataAvailable(Object sender, WaveInEventArgs e) in C:\Users\abc\Documents\Visual Studio 2008\Projects\sound\sound stream\Form1.cs:line 78
InnerException:
I posted the question on stackoverflow
Here's the Link and someone suggested to us HttpClient or Webclient so can i use them to send audio and if yes then how??
please help.