I'm using SmartGWT with RestDataSource. Whenever I lose internet connection, I get an SC.warn window with:
Server returned TRANSPORT_ERROR with no error message
I have tried to intercept this message to create a more friendly message, by adding a Callback handler for RPCManager like so:
RPCManager.setHandleTransportErrorCallback(new HandleTransportErrorCallback() {
public void handleTransportError(int transactionNum, int status,
int httpResponseCode, String httpResponseText) {
System.err.println("Transaction number: "+transactionNum);
System.err.println("Status: "+status);
System.err.println("Response code: "+httpResponseCode);
System.err.println("Response text:"+httpResponseText);
SC.warn("You have no internet connection.");
}
});
However, the Error messages print, and my warn message shows, but so does the system warn message above!
Keep in mind that I'm using a RestDataSource and not directly connecting to server with RPCManager.
How can I intercept this error message?
Thanks
Try instead RPCManager.setHandleErrorCallback(..).
Related
I have a scenario where I am trying to send multiple messages in one and trying to stream the one message from the gRPC server to the gRPC client side.
My proto files on server side look like this:
Service Greeter{
rpc AccumulateEvents (EventRequest) returns (stream EventsMessage);
}
message EventsMessage{
FirstEvent firstEvents =1;
SecondEvents secondEvent = 2;
}
message EventRequest{
//sending empty request
}
The service method is as follows:
public override async Task AccumulateEvents(EventRequest eventRequest, IServerStreamWriter < EventsMessage > responseStream, ServerCallContext context) {
IDisposable disposable4 = service.SubscribeToEvents(OnEvents);
service.execute();
await responseStream.WriteAsync(new EventsMessage {
FirstEvent = firstEvent, SecondEvents = secondEvents
});
}
When I am trying to fetch and parse the stream from the client side,i am getting null for secondEvent part of the message EventsMessage. Only firstEvents was returned from the server to the client. I tried debugging and could see secondEvent getting populated but then it became null when the streaming started from the server.
Also, secondEvent is a repeated field. I am not sure if that is the reason of it becoming null.
Please let me know what i might be missing here.
I use SignalR in an Angular app. When I destroy component in Angular I also want to stop connection to the hub. I use the command:
this.hubConnection.stop();
But I get an error in Chrome console:
Websocket closed with status code: 1006
In Edge: ERROR Error: Uncaught (in promise): Error: Invocation canceled due to connection being closed. Error: Invocation canceled due to connection being closed.
It actually works and connection has been stopped, but I would like to know why I get the error.
This is how I start the hub:
this.hubConnection = new HubConnectionBuilder()
.withUrl("/matchHub")
.build();
this.hubConnection.on("MatchUpdate", (match: Match) => {
// some magic
})
this.hubConnection
.start()
.then(() => {
this.hubConnection.invoke("SendUpdates");
});
EDIT
I finally find the issue. Its caused by change streams from Mongo. If I remove the code from SendUpdates() method then OnDisconnected is triggered.
public class MatchHub : Hub
{
private readonly IMatchManager matchManager;
public MatchHub(IMatchManager matchManager)
{
this.matchManager = matchManager;
}
public async Task SendUpdates() {
using (var changeStream = matchManager.GetChangeStream()) {
while (changeStream.MoveNext()) {
var changeStreamDocument = changeStream.Current.FullDocument;
if (changeStreamDocument == null) {
changeStreamDocument = BsonSerializer.Deserialize<Match>(changeStream.Current.DocumentKey);
}
await Clients.Caller.SendAsync("MatchUpdate", changeStreamDocument);
}
}
}
public override async Task OnDisconnectedAsync(Exception exception)
{
await base.OnDisconnectedAsync(exception);
}
}
Method GetChangeStream from the manager.
ChangeStreamOptions options = new ChangeStreamOptions() { FullDocument = ChangeStreamFullDocumentOption.UpdateLookup };
var watch = mongoDb.Matches.Watch(options).ToEnumerable().GetEnumerator();
return watch;
But I don't know how to fix it.
This can be for many reasons but i think it is most likely this one:
I think this is because of how the server is handling the connected / disconnected events. I can't say for sure but the connection closing needs to handled correctly on the server also with code. Try overriding the built in On Connected /Disconnected methods on the server and see. My assumption only is that you're closing it but the server isn't closing properly and therefore not relaying the proper closed response.
found as a comment at : getting the reason why websockets closed with close code 1006
Where you don't need to change the connection/disconection because evrything works fine. But as an answer this one is the most likely.
It throws error because the callback doesn't get clear properly.
And it is caused by the return data from websocket.
normally it should return like
However, for some reason it might return something like
the very last response breaking into 2 pieces
And that causes the issue.
I don't think there is a way to bypass this without changing the source code.
I reported this on github repo as well at here
It turns out that I can just utilize invocation response to notify client to stop the hub. So it doesn't trigger racing issue.
How to check the ERROR if the client is trying to connect to a absent server?
my code!
//Server
void Start () {
NetworkServer.Listen(13044);
}
//Client
NetworkClient thisclient = new NetworkClient ();
thisclient.Connect ("127.0.0.1", 13044);
thisclient.RegisterHandler(MsgType.Error, errortest);
thisclient.RegisterHandler (MsgType.Disconnect, dctest);
void errortest(NetworkMessage netMsg){
var errorMsg = netMsg.ReadMessage<ErrorMessage>();
Debug.Log("Error:" + errorMsg.errorCode);}
void dctest(NetworkMessage netMsg){
//if I run the client while the server is not present, its goes here instead of errortest
}
You are using ReadMessage with ErrorMessage, but ErrorMessage is only valid in Error messages (OnError).
Your dctest function is triggered on disconnection, not on error.
Disconnect is a special MsgType (see https://docs.unity3d.com/ScriptReference/Networking.MsgType.html) that (if I remember) doesn't contain any data.
So to answer your question : you already have the result. Everything is in netMsg.
https://docs.unity3d.com/Manual/UNetMessages.html
The ReadMessage function is mostly used with your own NetworkMessages, when you wand to send/read custom data.
Can anybody tell me how to receive message in muc using Smack 4.1.0 rc1?
I am able to send message using below code.
Message message = new Message();
message.setType(Message.Type.groupchat);
message.setBody(strMessage);
message.setTo(roomJid);
multiUserChat.sendMessage(message);
I am using below code but not able to get the message.
multiUserChat = multiUserChatManager.getMultiUserChat(roomJid);
multiUserChat.addMessageListener(new MessageListener() {
#Override
public void processMessage(Message message) {
Log.i(Constant.TAG, "processMessage");
}
});
My debugging is on and i can see that app is receiving message(D/SMACK( 6098): RECV (1):
) but listener is not getting called
Use MultiUserChat.addMessageListener(MessageListener).
send presence / join to muc before adding message listener to the muc.
then you will get muc message into the listener.
without sending presence or join to the muc, you can not get the message into the listener but you can see in the logcat.
I'm using stanza listener and able to receive MUC messages.
final StanzaListener stanzaListener = new StanzaListener() {
#Override
public void processStanza(Stanza packet) throws SmackException.NotConnectedException, InterruptedException { .. }
xmppConnection.addAsyncStanzaListener(stanzaListener, StanzaTypeFilter.MESSAGE);
I have created an application for FIX transactions using QuickFIX c++ API. The application is connecting to the server but the server sends "Provide UserName<553>" message. I looked for and result and found that i need to add username and password to the toAdmin method created this following code to in order to achieve that
void Application::toAdmin( FIX::Message& message, const FIX::SessionID& sessionID)
{
if (FIX::MsgType_Logon == message.getHeader().getField(FIX::FIELD::MsgType))
{
FIX44::Logon& logon_message = dynamic_cast<FIX44::Logon&>(message);
logon_message.setField(FIX::Username("my_username"));
logon_message.setField(FIX::Password("my_password"));
}
}
But then it throws and Exception. Please suggest what to do
remove this line and exception is handled
FIX44::Logon& logon_message = dynamic_cast<FIX44::Logon&>(message);
after that Put it
message.setField(FIX::Username("my_username"));
```````
message.setField(FIX::Password("my_password"));