Socket connection with Windows.Networking.Sockets and System.Net.Sockets - c#

I am trying to create a simple Windows Phone 8.1 (hence Windows.Networking.Sockets) socket client, and Windows 8 server. Unfortunately I am quite new to this task, so I am having problems understanding the obstacles that appear.
I am using http://msdn.microsoft.com/pl-pl/library/fx6588te(v=vs.110).aspx this code as a server. However when it comes to the Windows Phone 8.1, it turned out that http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202858(v=vs.105).aspx this tutorial won't work, as there is no way to use the following import:
using System.Net.Sockets.
Which is the reason why i switched to the following code:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj150599.aspx (which is btw quite sloppy, and full of errors)
So I embedded the Windows Phone 8.1 part of the code into my application, and it seems to connect correctly to the server, and it even sends data to the server, however the app crashes right after the following statement.
"Trying to send data"
And the output is exactly like the following:
A first chance exception of type 'System.ArgumentException' occured in Project.exe
WinRT information: count
Please help me solve the error, as I have vainly spent many hours trying to fix this..
EDIT
Here is the part of code from the mentioned tutorial, that throws the described error
// Now try to receive data from server
try
{
OutputView.Text = "";
StatusText.Text = "Trying to receive data ...";
DataReader reader = new DataReader(clientSocket.InputStream);
// Set inputstream options so that we don't have to know the data size
reader.InputStreamOptions = Partial;
await reader.LoadAsync(reader.UnconsumedBufferLength);
}

Related

Using NAudio with UDP and no microphone

I need to receive UDP data on a specified IP address and port, and convert it into a WAV file using C# and VS 2017. I did some Google’ing and read that NAudio can help do this. So I downloaded the NAudioDemo on https://github.com/naudio/NAudio, and opened the NAudioDemo project in VS 2017. After ensuring the NAudio NuGet package was restored I ran the project, selected the Network Chat demo to load and clicked the Load button.
This loaded the Network Chat demo.
I entered the correct IP Address and Port number in the text boxes, and made sure the Compression and Protocol values were set correctly.
You will notice in the screen shot the Input Device drop down hasn’t been set. This is because I’m running the demo on Windows Server 2012 R2, and the server doesn’t have any input devices setup and there is nothing in the drop down to select.
When I click the Start Streaming button it calls the NetworkChatPanel.Connect method, and this instantiates a new NetworkAudioPlayer object. Inside the constructor of the NetworkAudioPlayer class it runs the following code:
public NetworkAudioPlayer(INetworkChatCodec codec, IAudioReceiver receiver)
{
this.codec = codec;
this.receiver = receiver;
receiver.OnReceived(OnDataReceived);
waveOut = new WaveOut();
waveProvider = new BufferedWaveProvider(codec.RecordFormat);
waveOut.Init(waveProvider);
waveOut.Play();
}
It creates a new WaveOut object instance and calls the waveOut.Init method. This causes the following exception to be thrown:
An unhandled exception of type 'NAudio.MmException' occurred in
NAudio.dll BadDeviceId calling waveOutOpen occurred
I’m wondering if the exception was thrown because the server I’m running on has no input device(s). Or it could be something else.
Can you please help me get this running and working on Windows Server 2012 R2 with no input device(s), so I can save the UDP data as a WAV file?
Thank you.
Obviously with no soundcard you can't play audio. So get rid of all code relating to WaveOut, and create a WaveFileWriter instead. When you get a DataReceived event, write the received audio into the WaveFileWriter (with the Write method). Then make sure to Dispose the WaveFileWriter when you're done

C# Socket and ClearCase Dynamic View issue

I have a project under source control and I'm using a dynamic view. This project uses sockets. When I run the program I get an exception using this line of code:
var addresses = Dns.GetHostAddresses(Dns.GetHostName());
I get a socket exception with the following information:
Error Code: 11003
Message: "A non-recoverable error occurred during a database lookup"
Socket Error Code: NonRecovery
I don't have this issue running locally or on another windows network share (non-Clearcase). I believe this is a security issue related to sockets and network drives. I have a workaround but would really like to resolve this issue. I'm on Windows 7.
The first workaround would be to use a snapshot view instead of a dynamic one.
That way, you would be directly on the C drive instead of an MVFS mount point.
If you have to use dynamic view, make sure it is being accessed through its full path (no subst, no setview): M:\myview\myVob\...
Finally, it can depend on your exact ClearCase version: with ClearCase 7.x, there was socket error on Windows before: see "Unable to run executable that opens a socket on Microsoft Windows Vista, Windows Server 2008 or Windows 7"

NAudio - MediaFoundationReader: constructor doesn't take a delivered m4a-URL (from a youtube-Link)

I am trying to play an M4A (MP4 Audio) file directly from the internet using a URL.
I'm using NAudio with the MediaFoundation to achieve this:
using (var reader = new MediaFoundationReader(audioUrl)) //exception
using (var wave = new WaveOutEvent())
{
wave.Init(reader);
wave.Play();
}
This works well on two test systems with Windows 8.1 and Windows 10. But on my Windows 7 machine it is not working, I am getting an exception from inside the MediaFoundationReader constructor.
Initially, I was getting an ArgumentOutOfRangeException. I tested playing this m4a file in WMP and it was also unable to play it. I downloaded a codec pack and installed it. That helped with WMP but my code was still throwing an exception, albeit another one:
An unchecked exception of type
'System.Runtime.InteropServices.COMException' occurred in NAudio.dll
Additional information: There is more data available. (Exception from
HRESULT: 0x800700EA)
Any ideas what could be causing this and how I can fix it?
With some research i identified this
0X800700ea can occur when your Windows operating system becomes
corrupted. There can be numerous reason that this error occur
including excessive startup entries, registry errors, hardware/RAM
decline, fragmented files, unnecessary or redundant program
installations and so on.
Can you try you program in another system and verify
Sometimes the user doesn't have enough privileges to run COM Methods.
Try to run the application as Administrator.

Unable to open camera in window 8 store app using c#

I am the beginner on window 8 store app,still i am working on the app in which i have to open camera and capture the image, but when i try to execute following line of code, its throws following exception.
I am using following line of code
Windows.Media.Capture.CameraCaptureUI dialog = new CameraCaptureUI();
And throwing following exception
Requested Windows Runtime type 'Windows.Media.Capture.CameraCaptureUI' is not registered.
Please advise
thanks in advance
Maybe because you are on an emulator? Can you reproduce the error on a real device?

LoginWithApp always results in "Unable to communicate" response

I'm using the C# Facebook SDK for Windows & Windows Phone on Windows Phone 8 and trying to use the LoginWithApp approach:
public void Authenticate()
{
SessionStorage.Remove();
var client = new FacebookSessionClient(this.appId);
client.LoginWithApp("basic_info,read_stream,read_friendlist", "custom_state_string");
}
If I use the above code, it works fine in the emulator using the Login Simulator, but on a physical device I always get the following error response:
"(No connection to facebook - #2002) Connection failed: Unable to communicate with facebook in order to get the access token"
However, this can't be a simple communication problem because if I remove the read_friendlist permission it works every time.
Can anyone explain what's going on and how to fix this, please?
read_friendlist should be read_friendlists with an S on the end.

Categories

Resources