I'm running very simple signalr server self-hosted via Owin on ubuntu server 14.04, mono 3.2.8. (code below).
Connecting/Disconnecting works fine on both a remote windows server and when I deploy the bits to the linux server. But when a client dies unexpectedly instead of telling signalr that he's disconnecting, that's when I get a never-ending SocketException only on the linux server only. The windows server disconnects the client after about 30 seconds or so, but the linux server spews the socketexception (also below) every 10 seconds or so, forever.
How can I make the linux server behave like the windows server when running the same code, disconnect the user after a set timeout and not throw socketexceptions?
Server Code:
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Owin;
namespace signalrtestserver
{
class Program
{
static void Main(string[] args)
{
var uri = System.Configuration.ConfigurationManager.AppSettings["startup_uri"] ?? "http://*:7890";
using (Microsoft.Owin.Hosting.WebApp.Start<Startup>(uri))
{
Console.WriteLine(string.Format("Server started on {0}. Press enter to close.", uri));
Console.ReadLine();
}
}
}
class Startup
{
static Hub hub;
public void Configuration(IAppBuilder app)
{
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
var configuration = new HubConfiguration();
configuration.EnableDetailedErrors = true;
app.MapSignalR("/signalr", configuration);
hub = new MyHub();
}
}
public class MyHub : Hub
{
public override Task OnConnected() { Console.WriteLine(Context.ConnectionId + " connected"); return base.OnConnected(); }
public override Task OnDisconnected() { Console.WriteLine(Context.ConnectionId + " disconnected"); return base.OnDisconnected(); }
public override Task OnReconnected() { Console.WriteLine(Context.ConnectionId + " reconnected"); return base.OnReconnected(); }
}
}
Client Code:
using System;
using System.Net;
using Microsoft.AspNet.SignalR.Client;
namespace signalrconnection
{
class Program
{
static void Main(string[] args)
{
var uri = System.Configuration.ConfigurationManager.AppSettings["signalr_uri"] ?? "http://localhost:7890/signalr";
ServicePointManager.DefaultConnectionLimit = 10;
var hubConnection = new HubConnection(uri, false);
hubConnection.StateChanged += stateChange => Console.WriteLine(string.Format("SignalR {0} >> {1} ({2})", stateChange.OldState, stateChange.NewState, hubConnection.Transport == null ? "<<null>>" : hubConnection.Transport.Name));
var hubProxy = hubConnection.CreateHubProxy("MyHub");
hubConnection.Start();
Console.WriteLine("Press enter to die...");
Console.ReadLine();
//hubConnection.Dispose(); //uncomment this to simulate a graceful disconnect which works on both windows and linux
}
}
}
Never-Ending Mono Exception:
{path-to-project}/Microsoft.AspNet.SignalR.Core.dll Error : 0 : SignalR exception thrown by Task: System.AggregateException: One or more errors occured ---> System.IO.IOException: Write failure ---> System.Net.Sockets.SocketException: Connection reset by peer
at System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags) [0x00000] in <filename unknown>:0
at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
at System.Net.ResponseStream.InternalWrite (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
at System.Net.ResponseStream.Write (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
at Microsoft.Owin.Host.HttpListener.RequestProcessing.ExceptionFilterStream.Write (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
--> (Inner exception 0) System.IO.IOException: Write failure ---> System.Net.Sockets.SocketException: Connection reset by peer
at System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags) [0x00000] in <filename unknown>:0
at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
at System.Net.ResponseStream.InternalWrite (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
at System.Net.ResponseStream.Write (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
at Microsoft.Owin.Host.HttpListener.RequestProcessing.ExceptionFilterStream.Write (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
Any help would be much appreciated. Thanks in advance!
The problem is this line static Hub hub, and this one hub = new MyHub() in your Startup method.
You do not need to explicitly create instances of the Hub class, neither do you need to keep a reference around. The hub class is instantiated on every request to the server. See
http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-server#transience the section on Hub object lifetime.
This means that whenever there is a disconnection, Mono in Linux is throwing a different exception than MS.NET in Windows. SignalR was implemented by people which were most likely using MS.NET and therefore SignalR must be expecting certain exception and be religious about this.
The best way to fix this is debug the code stepping into SignalR implementation (when running on Linux with Mono) to see where is the exception being caught, and compare to what happens in SignalR under MS.NET in Windows. Then create a minimal testcase about the difference and submit a bug in http://bugzilla.xamarin.com/, they will probably fix it soon (or you can assign it to me and I'll look at it, because I have interest in running SignalR under mono).
I had the same issue on Raspberry Pi with simple Owin self hosted demo app. Requesting "welcome" page from single browser by holding F5 was enough to kill the host within 15 seconds. I have not done any automated stress testing yet, as my "user acceptance" test was failing right away.
The reliable solution I found is to create custom OwinMiddleware to catch and jam the socket exception:
class CustomExceptionMiddleware : OwinMiddleware
{
public CustomExceptionMiddleware(OwinMiddleware next)
: base(next)
{
}
public override async Task Invoke(IOwinContext context)
{
try
{
await Next.Invoke(context);
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
}
}
The Owin startup will need to be updated to use the middleware:
using Owin;
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Use<OwnExceptionMiddleware>()
.UseNancy();
}
}
It was inspired by http://dhickey.ie/2014/02/bubbling-exceptions-in-nancy-up-the-owin-pipeline/
Here is my exception for reference:
Unhandled Exception:
System.IO.IOException: Write failure ---> System.Net.Sockets.SocketException: The socket has been shut down
at System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags) [0x00000] in <filename unknown>:0
at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
at System.Net.ResponseStream.InternalWrite (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
at System.Net.ResponseStream.Close () [0x00000] in <filename unknown>:0
at System.Net.HttpConnection.Close (Boolean force_close) [0x00000] in <filename unknown>:0
at System.Net.HttpListenerResponse.Close (Boolean force) [0x00000] in <filename unknown>:0
at System.Net.HttpListenerResponse.Abort () [0x00000] in <filename unknown>:0
at Microsoft.Owin.Host.HttpListener.RequestProcessing.OwinHttpListenerResponse.End () [0x00000] in <filename unknown>:0
at Microsoft.Owin.Host.HttpListener.RequestProcessing.OwinHttpListenerContext.End () [0x00000] in <filename unknown>:0
at Microsoft.Owin.Host.HttpListener.RequestProcessing.OwinHttpListenerContext.End (System.Exception ex) [0x00000] in <filename unknown>:0
at Microsoft.Owin.Host.HttpListener.OwinHttpListener+<ProcessRequestAsync>d__5.MoveNext () [0x00000] in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0
at Microsoft.Owin.Host.HttpListener.OwinHttpListener+<ProcessRequestsAsync>d__0.MoveNext () [0x00000] in <filename unknown>:0
Consider being specific in what exceptions you intercept:
public override async Task Invoke(IOwinContext context)
{
try
{
await Next.Invoke(context);
}
catch (IOException ex)
{
if (ex.HResult == -2146233087) // The socket has been shut down
{
NLog.LogManager.GetLogger("OwinExceptionHandler").Trace(ex);
}
else
{
throw;
}
}
}
I think I have the same problem. I described it:
https://katanaproject.codeplex.com/workitem/438
https://bugzilla.xamarin.com/show_bug.cgi?id=33254#c4
I've found solution for my situation. I set HttpListener.IgnoreWriteExceptions property to 'true' in OWIN configuration method and then register middlewares. For example:
internal class Startup
{
public void Configuration(IAppBuilder app)
{
object httpListener;
if (app.Properties.TryGetValue(typeof(HttpListener).FullName, out httpListener)
&& httpListener is HttpListener)
{
// HttpListener should not return exceptions that occur
// when sending the response to the client
((HttpListener)httpListener).IgnoreWriteExceptions = true;
}
app.Use<TestOwinMiddleware>();
}
}
I hope this may help you.
Related
I have a Mono .NET application that uses ppatierno.AzureSBLite to receive data from an Azure ServiceBus.
The code is straightforward:
var factory = MessagingFactory.CreateFromConnectionString(connectionString);
var client = factory.CreateEventHubClient(eventHubEntity);
var group = client.GetDefaultConsumerGroup();
var receiver = group.CreateReceiver(partitionId, startingDateTimeUtc);
EventData = receiver.Receive();
On my VM running 64-bit Ubuntu 16.04, using Ubuntu's Mono packages, it works flawlessly.
On my build server running Ubuntu 14.04, in a 64-bit 16.04 chroot (so the chroot environment should have all of the same userland packages as the VM), using Ubuntu's Mono packages, I get the following error:
System.Net.Sockets.SocketException: Invalid arguments
at System.Net.Sockets.Socket.BeginMConnect (System.Net.Sockets.SocketAsyncResult sockares) <0x41029e20 + 0x001df> in <filename unknown>:0
at System.Net.Sockets.Socket.BeginConnect (System.Net.IPAddress[] addresses, Int32 port, System.AsyncCallback callback, System.Object state) <0x41029720 + 0x00107> in <filename unknown>:0
at System.Net.Sockets.Socket.BeginConnect (System.String host, Int32 port, System.AsyncCallback callback, System.Object state) <0x41027720 + 0x0008f> in <filename unknown>:0
at Amqp.TcpTransport+<>c__DisplayClass3.<ConnectAsync>b__0 (System.AsyncCallback c, System.Object s) <0x41027670 + 0x00073> in <filename unknown>:0
at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncImpl (System.Func`3 beginMethod, System.Func`2 endFunction, System.Action`1 endAction, System.Object state, TaskCreationOptions creationOptions) <0x7fc54c2c8700 + 0x001cf> 24334 in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x7fc54c0016d0 + 0x00029> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) <0x7fc54bfff6b0 + 0x000a7> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) <0x7fc54bfff630 + 0x0006b> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) <0x7fc54bfff5e0 + 0x0003a> in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () <0x7fc54bfff5c0 + 0x00012> in <filename unknown>:0
at Amqp.TcpTransport.Connect (Amqp.Connection connection, Amqp.Address address, Boolean noVerification) <0x410219b0 + 0x0015e> in <filename unknown>:0
at Amqp.Connection.Connect (Amqp.Sasl.SaslProfile saslProfile, Amqp.Framing.Open open) <0x41021680 + 0x0006b> in <filename unknown>:0
at Amqp.Connection..ctor (Amqp.Address address, Amqp.Sasl.SaslProfile saslProfile, Amqp.Framing.Open open, Amqp.OnOpened onOpened) <0x4101ba40 + 0x00227> in <filename unknown>:0
at Amqp.Connection..ctor (Amqp.Address address) <0x4101b9b0 + 0x0001b> in <filename unknown>:0
at ppatierno.AzureSBLite.Messaging.Amqp.AmqpMessagingFactory.Open (System.String entity) <0x4101b760 + 0x001b7> in <filename unknown>:0
at ppatierno.AzureSBLite.Messaging.Amqp.AmqpMessageReceiver.ReceiveEventData () <0x4101afb0 + 0x00042> in <filename unknown>:0
at ppatierno.AzureSBLite.Messaging.EventHubReceiver.Receive () <0x4101ab40 + 0x0001f> in <filename unknown>:0
at ReceiveEdgeData.EdgeReceiver.MainLoop () <0x4101a920 + 0x0004b> in <filename unknown>:0
If I understand the strace output correctly, the non-functioning host is creating an IPv6 socket and trying to directly connect to an IPv4 address:
connect(4, {sa_family=AF_INET, sin_port=htons(5671), sin_addr=inet_addr("52.176.47.198")}, 16) = -1 EINVAL (Invalid argument)
While the functioning host is using something like dual-mode sockets to correctly represent the IPv4 address as an IPv6 address:
connect(4, {sa_family=AF_INET6, sin6_port=htons(5671), inet_pton(AF_INET6, "::ffff:52.176.47.198", &sin6_addr), sin6_flowinfo=htonl(0), sin6_scope_id=0}, 28) = -1 EINPROGRESS (Operation now in progress)
Given that this is happening somewhere inside Mono and its dependencies, how do I troubleshoot and fix this?
I've been running SignalR on mono with both self-hosting on localhost and on IIS.
But self-hosting with mono on a server didn't work yet
The full error I get on the webpage is:
System.InvalidOperationException
Operation is not valid due to the current state of the object.
Description:` HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): Microsoft.Owin.Host.SystemWeb.
Exception stack trace:
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.BeginEvent (System.Object sender, System.EventArgs e, System.AsyncCallback cb, System.Object extradata) <0x404788f0 + 0x0074b> in <filename unknown>:0
at System.Web.HttpApplication+<RunHooks>c__Iterator0.MoveNext () <0x404715e0 + 0x00367> in <filename unknown>:0
at System.Web.HttpApplication+<Pipeline>c__Iterator1.MoveNext () <0x40468000 + 0x01a65> in <filename unknown>:0
at System.Web.HttpApplication.Tick () <0x40465950 + 0x00057> in <filename unknown>:0
In the Apache error log:
Cannot access a closed Stream.
at System.IO.MemoryStream.Write (System.Byte[] buffer, Int32 offset, Int32 count) <0x4006e720 + 0x0008b> in <filename unknown>:0
at System.IO.BinaryWriter.Write (Int32 value) <0x4006e660 + 0x00087> in <filename unknown>:0
at Mono.WebServer.ModMonoRequest.IsConnected () <0x40540670 + 0x0001f> in <filename unknown>:0
at Mono.WebServer.Apache.ModMonoWorker.IsConnected () <0x40540640 + 0x0001b> in <filename unknown>:0
at Mono.WebServer.ModMonoWorkerRequest.IsClientConnected () <0x405405b0 + 0x00030> in <filename unknown>:0
at System.Web.HttpResponse.get_IsClientConnected () <0x40540570 + 0x0002a> in <filename unknown>:0
at System.Web.HttpResponseWrapper.get_IsClientConnected () <0x40540540 + 0x0001b> in <filename unknown>:0
at Microsoft.Owin.Host.SystemWeb.OwinCallContext.CheckIsClientConnected (System.Object obj) <0x40540490 + 0x00051> in <filename unknown>:0
at System.Threading.Timer+Scheduler.TimerCB (System.Object o) <0x4053daf0 + 0x001a7> in <filename unknown>:0
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () <0x403d3c60 + 0x0002f> in <filename unknown>:0
at System.Threading.ThreadPoolWorkQueue.Dispatch () <0x403d09b0 + 0x0021a> in <filename unknown>:0
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () <0x403d0980 + 0x00010> in <filename unknown>:0
My code looks just fine, my program.cs contains:
class Program
{
static void Main(string[] args)
{
string url = "http://*:80";
using (Microsoft.Owin.Hosting.WebApp.Start<Startup>(url))
{
}
}
}
I have no idea what to do, should I look to change something in my code to let it work with mono?
I'm going to use SignalR Core, problem solved! :)
I'm running Arch Linux with the following version of mcs:
>mcs --version
Mono C# compiler version 4.0.4.0
And the following version of dbus-sharp
>pacman -Ss dbus-sharp
extra/dbus-sharp 0.8.1-1 [installed] C# implementation of D-Bus
extra/dbus-sharp-glib 0.6.0-1 [installed] C# GLib implementation of D-Bus
This is my test program, based on the example code found here: https://gist.github.com/Ummon/4317268
I'm just trying to access the settings of the currently active connection, which should be returned as a 'Dict of {String, Dict of {String, Variant}}' as I've checked in the d-feet tool for the org.freedesktop.NetworkManager.Settings.Connection interface
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using DBus;
namespace NetworkManagerDictTest {
public class MyTest {
[Interface("org.freedesktop.NetworkManager.Settings.Connection")]
public interface IConnection {
IDictionary<string, IDictionary<string, object>> GetSettings();
}
readonly static string BUS_NAME = "org.freedesktop.NetworkManager";
public static void Main(string[] argv) {
org.freedesktop.DBus.Properties NetworkManagerProps = Bus.System.GetObject<org.freedesktop.DBus.Properties>(BUS_NAME, new ObjectPath("/org/freedesktop/NetworkManager"));
ObjectPath[] activeConnections = NetworkManagerProps.Get(BUS_NAME, "ActiveConnections") as ObjectPath[];
if (activeConnections.Length > 0) {
org.freedesktop.DBus.Properties ActiveConnectionProperties = Bus.System.GetObject<org.freedesktop.DBus.Properties>(BUS_NAME, activeConnections[0]);
ObjectPath ActiveConnectionPath = ActiveConnectionProperties.Get("org.freedesktop.NetworkManager.Connection.Active", "Connection") as ObjectPath;
Console.WriteLine("Using connection path: " + ActiveConnectionPath);
IConnection connection = Bus.System.GetObject<IConnection>(BUS_NAME, ActiveConnectionPath);
Console.WriteLine("Connection Object ok");
IDictionary<string, IDictionary<string, object>> settings = connection.GetSettings();
Console.WriteLine(settings);
}
}
}
}
Compilation went without errors nor warnings:
mcs Test.cs -r:/usr/lib/mono/dbus-sharp-2.0/dbus-sharp.dll -r:/usr/lib/mono/dbus-sharp-glib-2.0/dbus-sharp-glib.dll
However my program crashes during execution with the following output:
>mono Test.exe
Using connection path: /org/freedesktop/NetworkManager/Settings/0
Connection Object ok
Unhandled Exception:
DBus.Protocol.MessageReader+PaddingException: Read non-zero byte at position 28 while expecting padding. Value given: 200
at DBus.Protocol.MessageReader.ReadPad (Int32 alignment) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadStruct (System.Type type) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadValue (System.Type type) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadDictionary[String,IDictionary`2] () [0x00000] in <filename unknown>:0
at NetworkManagerDictTest.MyTest+IConnectionProxy.GetSettings () [0x00000] in <filename unknown>:0
at NetworkManagerDictTest.MyTest.Main (System.String[] argv) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: DBus.Protocol.MessageReader+PaddingException: Read non-zero byte at position 28 while expecting padding. Value given: 200
at DBus.Protocol.MessageReader.ReadPad (Int32 alignment) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadStruct (System.Type type) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadValue (System.Type type) [0x00000] in <filename unknown>:0
at DBus.Protocol.MessageReader.ReadDictionary[String,IDictionary`2] () [0x00000] in <filename unknown>:0
at NetworkManagerDictTest.MyTest+IConnectionProxy.GetSettings () [0x00000] in <filename unknown>:0
at NetworkManagerDictTest.MyTest.Main (System.String[] argv) [0x00000] in <filename unknown>:0
What can I do to work around this problem? Am I making a mistake when working with the DBus? It seems that all the method calls up to GetSettings went without issues. I've also encountered a similar problem while trying to fix a bug in another project where dbus-sharp would throw an exception when calling GetSettings. Could this be an issue of dbus-sharp instead?
Taking a look at the source code it seems that dbus-sharp infers the return type directly from the signature of the declared method. Unfortunately it doesn't check if I'm using a parent class or interface of Dictionary, eventually it tries to read a DBus struct because of a fallback case which causes the exception as DBus structs are 8 byte padded while dicts use 4 bytes
Replacing all the IDictionary types with Dictionary worked fine and solved my problem.
I'm trying to use Raspberry# library to perform basic task whith GPIO pin on Raspberry PI (on and off).
As per example on github: https://github.com/raspberry-sharp/raspberry-sharp-io/wiki/Raspberry.IO.GeneralPurpose
Code:
var led1 = ConnectorPin.P1Pin11.Output();
var connection = new GpioConnection(led1);
for (var i = 0; i < 100; i++)
{
connection.Toggle(led1);
System.Threading.Thread.Sleep(250);
}
connection.Close();
on line var connection = new GpioConnection(led1); I get exception:
"Operation is not valid due to the current state of the object"
Stack trace
Unhandled Exception:
System.InvalidOperationException: Operation is not valid due to the current state of the object
at Raspberry.IO.GeneralPurpose.GpioConnectionDriver..ctor () [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnectionSettings.get_DefaultDriver () [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnectionSettings..ctor () [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.GpioConnectionSettings settings, IEnumerable`1 pins) [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.PinConfiguration[] pins) [0x00000] in <filename unknown>:0
at Hello.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: Operation is not valid due to the current state of the object
at Raspberry.IO.GeneralPurpose.GpioConnectionDriver..ctor () [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnectionSettings.get_DefaultDriver () [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnectionSettings..ctor () [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.GpioConnectionSettings settings, IEnumerable`1 pins) [0x00000] in <filename unknown>:0
at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.PinConfiguration[] pins) [0x00000] in <filename unknown>:0
at Hello.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
I am able to switch pin state with Python so nothing is wrong with device.
Execute your Mono program as root. /dev/mem is not accessible to normal users.
public GpioConnectionDriver() {
using (var memoryFile = UnixFile.Open("/dev/mem", UnixFileMode.ReadWrite | UnixFileMode.Synchronized)) {
gpioAddress = MemoryMap.Create(
IntPtr.Zero,
Interop.BCM2835_BLOCK_SIZE,
MemoryProtection.ReadWrite,
MemoryFlags.Shared,
memoryFile.Descriptor,
Interop.BCM2835_GPIO_BASE
);
}
}
Explanation from here:
http://www.raspberrypi.org/forums/viewtopic.php?f=29&t=22515
To open /dev/mem you need both regular access permissions on the device file and the security capability CAP_SYS_RAWIO, or to be root. There is no getting around this, because full access to memory allows a lot more than just GPIO. It has huge security implications.
Okay so I have came to an issue that I thought I fixed with a crappy rig and it failed in the long run, so I came to ask you guys the correct way to do it. Here is the issue I have, i'm making an application to filter out a certain type of email via POP3 (using the ActiveUp api) but I need it to have a constant connection to the POP3 server...this is what I have right now:
public static void Main (string[] args)
{
while(true)
{
POP3();
Console.Title = "Waiting for "+GetSubject+POST;
Thread.Sleep(5000);
}
}
public static void POP3()
{
Pop3Client pop3 = new Pop3Client();
try
{
pop3.ConnectSsl("pop.gmail.com",995,"", "");
if(pop3.MessageCount > 0)
{
int CurrentMessage = pop3.MessageCount;
ActiveUp.Net.Mail.Message message = pop3.RetrieveMessageObject(CurrentMessage);
if(message.Subject == GetSubject+POST)
{
Console.WriteLine("command reconized from {0}: {1}\n Sending responce now!",message.From.Email, message.Subject);
SMTP (message.From.Email, _message);
POST++;
pop3.Close();
}
}
else
{
Console.WriteLine("no mail found");
}
}
catch(Pop3Exception iex)
{
Console.WriteLine(iex);
pop3.Close();
}
}
Everything works perfect until about 10-20 minuets of it running I get kicked off of google's POP3 server and have to restart the application...Ill run the application now and reedit my question with the error...but until then can you guys please help me? Thanks!
Error:
nhandled Exception: System.Net.Sockets.SocketException: No such host is known
at System.Net.Dns.hostent_to_IPHostEntry (System.String h_name, System.String[] h_aliases, System.String[] h_addrlist) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostByName (System.String hostName) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.String hostname, Int32 port) [0x00000] in <filename unknown>:0
at ActiveUp.Net.Mail.Pop3Client.ConnectSsl (System.String host, Int32 port, System.String user, System.String pass, ActiveUp.Net.Security.SslHandShake sslHandShake) [0x00000] in <filename unknown>:0
at ActiveUp.Net.Mail.Pop3Client.ConnectSsl (System.String host, Int32 port, System.String user, System.String pass) [0x00000] in <filename unknown>:0
at AutoThreadOwnerCopy.MainClass.POP3 () [0x00006] in /home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:35
at AutoThreadOwnerCopy.MainClass.Main (System.String[] args) [0x00019] in /home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:25
[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException: No such host is known
at System.Net.Dns.hostent_to_IPHostEntry (System.String h_name, System.String[] h_aliases, System.String[] h_addrlist) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostByName (System.String hostName) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.String hostname, Int32 port) [0x00000] in <filename unknown>:0
at ActiveUp.Net.Mail.Pop3Client.ConnectSsl (System.String host, Int32 port, System.String user, System.String pass, ActiveUp.Net.Security.SslHandShake sslHandShake) [0x00000] in <filename unknown>:0
at ActiveUp.Net.Mail.Pop3Client.ConnectSsl (System.String host, Int32 port, System.String user, System.String pass) [0x00000] in <filename unknown>:0
at AutoThreadOwnerCopy.MainClass.POP3 () [0x00006] in /home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:35
at AutoThreadOwnerCopy.MainClass.Main (System.String[] args) [0x00019] in /home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:25