Error Code 2147500037 on Attempt for Bluetooth Connection in Windows Phone 8 - comexception

I am attempting to establish an app-to-app bluetooth connection programmatically. Please see the following code snippet for the said purpose:
StreamSocket streamSocket = await PeerFinder.ConnectAsync(peerInformation);
I get this error whenever I try to do so:
An exception of type `System.Runtime.InteropServices.COMException` occurred
in mscorlib.ni.dll and wasn't handled before a managed/native boundary
HRESULT E_FAIL has been returned from a call to a COM component.
ERROR CODE: 2147500037
Please advise on how to go around with this error.

Related

Flutter/Dart + gRPC Stream error: Stream was terminated by peer (errorCode: 2)

I'm having this intermittent error come up when making a call from a Dart gRPC client to a Go gRPC server. The exact error message is:
gRPC Error (code: 2, codeName: UNKNOWN, message: HTTP/2 error: Stream
error: Stream was terminated by peer (errorCode: 2)
This seems to occur frequently on creating the client stub with the channel and making a call to the server. Subsequent calls seems to work fine with a response returned correctly to the client. Then this error intermittently pops up again every n-th call (could be after 5 calls, 10 calls sometimes no errors until the 20th call).
When I use a different client (eg: BloomRPC or Java app I wrote), this does not happen no matter how hard or fast I spam the calls to the server. This kind of implies the server is probably not the issue.
Can anyone shine a light on what might be happening? Or provide some hints as to where to start looking/debugging? I've tried stepping through the code, but not really able to follow what is happening when the gRPC call is made/returned.
Steps in the client code:
create ClientChannel with ip, ports
final cc = ClientChannel(serverIP,
port: serverPort,
options:
const ChannelOptions(credentials: ChannelCredentials.insecure()
));
created a stub based on above channel
_userQueryStub = UserQueryGRPCClient(cc,
options: CallOptions(timeout: Duration(seconds: 30)));
call function from stub (repeatedly)
GetUserInformationRequest request = GetUserInformationRequest(userId: userId);
GetUserInformationResponse response = await _userQueryStub.getUserInformation(request);
Any help will be greatly appreciated!

Failed to read HTTP message:ion: JSON parse error: Unexpected end-of-input in VALUE_STRING : Unexpected EOF read on the socket

When a client is sending an image to one of the rest endpoints, only part of the data is being received.
To be sure what is happening I made a trace with Wireshark and analyzed it. The application is indeed not receiving the last part of the message. This is because the application is not able to receive all the data within the 900ms timeout that is specified on the Client side. Its buffers are full halfway through the reception.
I get application warning
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver
[http-nio-0.0.0.0-9999-exec-35] Failed to read HTTP message:
org.springframework.http.converter.HttpMessageNotReadableException:
I/O error while reading input message; nested exception is
java.io.EOFException: Unexpected EOF read on the socket
And the client gets Connection timeout.
I have got a solution to my problem. I have increased the socket buffer size in my application. I have added following code to my Application class.
#Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = new TomcatEmbeddedServletContainerFactory();
tomcatEmbeddedServletContainerFactory.setProtocol("org.apache.coyote.http11.Http11Nio2Protocol");
tomcatEmbeddedServletContainerFactory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
connector.setProperty("socket.rxBufSize", "5000000");
});
return tomcatEmbeddedServletContainerFactory;
}

libpq: How to get the error code after a failed PGconn connection

Given the following code.
PGconn* const conn=PQconnectdbParams(keywords, values, false);
if(! conn || PQstatus(conn)!=CONNECTION_OK){ /* error code? */ }
In case of a failed connection is there a way to get the error code to be able to
distinguish between a bad password and the server being down.
(I know I can get the error message, but I want to be able to react to the cause of the
error according to its cause).
Thanks.
So after doing some more research and asking postgres developers it seems that it is not currently possible to get the error code from PQconnectdbParams().
This seems to be a shortcoming of libpq itself which doesn't try to assign SQLState error codes for errors it detects internally (like an unknown hostname).
This seems to be on the postgres dev todo list but it's not a priority.
TL;DR: If you are going to use libpq, learn to live with the text error message (whatever language it is localized in).
Try...
cout << PQerrorMessage(conn) << endl;
Try to call getpeername() on PQsocket(conn).
In case of server being down getpeername return error, but in case of wrong password tcp connection was successfully established, and getpeername return server address.

Zend framework- how to stop execution and redirect to the error controller

I want to catch php errors so i used set_error_handler('handler_function') when i echo the error message , 'Zend_Controller_Response_Exception' with message 'Cannot send headers; headers already sent' is thrown when i used the following lines
$fc=Zend_Controller_Front::getInstance();
$fc->getResponse()->setBody($error);
an error happened 'call to setBody method of a non-object'
i tried to throw an exception from the error handler but this depend on the error occurring before bootstrapping is displayed directly after bootstrapping displayed in errorController
i used $fc->throwExceptions(false) to ensure it will send exceptions to error controller
when i do nothing in the error handler the execution is continued
what i need is to have one place to handle all errors
if there is a way to redirect to the error controller with error in params this will be good
IMO best way to handle these errors is to register error handler that will convert any error/fatal error to exception. I guess that response is not created yet. You have to use $fc's setResponse() method to create new response. I would guess that converting to exception should work in any case. Same as exceptions from Zend classes work.

Exception Handling in REST

I have created a REST service using WCF for communicating with BLL/DAL from UI. Now, I would like to implement Exception Handling through some globalize way in REST. I am using HTTPClient to communicate with REST from client. The following are the ways, I have implemented exception handling:
Approach 1:
OutgoingWebResponseContext response = WebOperationContext.Current.OutgoingResponse;
response.StatusCode = System.Net.HttpStatusCode.Unauthorized;
response.StatusDescription = ex.Message;
success = false;
Approach 2:
throw new WebProtocolException(HttpStatusCode.NotFound, ex.Message, null);
but somehow I am not able to catch them in the client side. Kindly suggest some pointers in order to handle exceptions raised by service globally.
I am throwing WebProtocolException (Approach 2) along with error code and error message from the service to UI in order to notify users about the exception. I am able to receive the error code in UI side but not getting error message or detail.
Then I created another service (having .svc extension) and added following line to the service's markup: "Factory='Microsoft.ServiceModel.Web.WebServiceHost2Factory'". Now, I am able to receive the error message along with error code on client side (UI).
Can anybody let me know how to use the WebServiceHost2Factory method in my existing service which is a class file instead of .svc file?
Any suggestions will be highly appreciated. Thanks
HttpClient does not throw exceptions when a response comes back that is not "successful". If you really want exceptions to be thrown on the client side, then call
response.EnsureResponseIsSuccessful();
Otherwise, just check the status code on the client and decide what to do based on that value.
You cannot throw exceptions on the server and expect the exceptions to be propagated to the client. HTTP does not have any notion of exception.