SendResponse method issue

Nov 8, 2012 at 7:09 PM

Hi,

I have one application that receives connections from users, store them on a list, each user has a reference to its session class. 

I generate information on the windows form that needs to be sent to all users, on a separate thread I store the information that needs to be sent to users after a parametrized delay, after this time is consumed, the information is sent.

I have multiple try/catch sections to manage every possible issue, I have logs about the information that is being sent and serialized on json format, at some point the class in charge of sending messages to the players stops working, it's like the thread disappears completely, but any exception is raised, the last point of the process is when we call the SendResponse method on my Session class.

I have no information on the error log generated by your classes, same situation also with the logs for my application.

Remotely debugging the application is not an option right now, only thing we had were the logs. 

We are using SuperSocket 1.4 SP5

Coordinator
Nov 9, 2012 at 12:53 AM

Could you show me the code how you get the session and then send message?

Nov 9, 2012 at 1:08 AM

Hi,

On my Server class I inserted a method to get the Session class and I throw one event that contains the session inside, this event is observed by my main application.

public override Session CreateAppSession(ISocketSession socketSession) {

  Session newSession = base.CreateAppSession(socketSession);

if (Connected != null) 

Connected(this, new ServerConnectionEventArgs(newSession));

return newSession;

}

 

Then, my user class has a reference to the session I got from previous step, inside my Session class I created a method to send the data, this one is called by the class I mentioned is in a separate thread, reading messages from a pool. My main concern is that I don't catch any exception on the process, my thread that is reading from the pool just stops.

public void SendMessage(String jsonData) {

try {

List<byte> message = new List<byte>();

message.AddRange(CommandReader.StartMark);

message.AddRange(Encoding.ASCII.GetBytes(jsonData));

message.AddRange(CommandReader.EndMark);

this.AppServer.Logger.LogInfo("broadcast arrray created and ready to send " + this.SessionID + " status " + this.Status);

this.SendResponse(message.ToArray());

this.AppServer.Logger.LogInfo("broadcast sent " + this.SessionID + " status " + this.Status + " " + jsonData);

}

catch (Exception nee) {

this.AppServer.Logger.LogInfo("issue error sending message " + jsonData + " " + nee.Message + " " + nee.StackTrace);

}

}

Thanks for your time answering my question.

Coordinator
Nov 9, 2012 at 1:09 AM

Did you handle the session closed event?

Nov 9, 2012 at 1:21 AM

On my server class I made a override for OnAppSessionClosed to notify my application that the user closed the application

protected override void OnAppSessionClosed(object sender, AppSessionClosedEventArgs<Session> e) {

  base.OnAppSessionClosed(sender, e);

if (Disconnected != null)

Disconnected(this, new ServerConnectionEventArgs(e.Session));

}

Also tried to override the Close method on my session class to see if the problem was that the session was closed, but while debugging, the breakpoint never hit on that section, even when I forced an exception inside the SendResponse method.

public override void Close() { base.Close(); }
public override void Close(CloseReason reason) { base.Close(reason); }

Coordinator
Nov 9, 2012 at 1:23 AM

Do you mean this line never be fired?

this.AppServer.Logger.LogInfo("broadcast sent " + this.SessionID + " status " + this.Status + " " + jsonData);

Nov 9, 2012 at 1:28 AM

Yes, that's what happened.

Just to be sure about what is happening, one hour ago I generated a temporal version of the supersocket solution that is generating extra logs inside the methods of the AppSession, AsyncSocketSession and the SocketEx classes, on the methods related with the SendResponse call, so far this hasn't happened again so I have no logs about this.

Coordinator
Nov 9, 2012 at 1:30 AM

You should add a log line before the code line:

this.SendResponse(message.ToArray());

Nov 9, 2012 at 1:34 AM

I already discarted that option, previous version of my code was like following, but the result was the same.

public void SendMessage(String jsonData) {

try {

List<byte> message = new List<byte>();

byte[] byteMessage;

message.AddRange(CommandReader.m_StartMark);

message.AddRange(Encoding.ASCII.GetBytes(jsonData));

message.AddRange(CommandReader.m_EndMark);

byteMessage = message.ToArray();

this.AppServer.Logger.LogInfo("broadcast arrray created and ready to send " + this.SessionID + " status " + this.Status);

this.SendResponse(byteMessage);

this.AppServer.Logger.LogInfo("broadcast sent " + this.SessionID + " status " + this.Status + " " + ASCIIEncoding.ASCII.GetString(byteMessage ));

}

catch (Exception nee) {

this.AppServer.Logger.LogInfo("issue error sending message " + jsonData + " " + nee.Message + " " + nee.StackTrace);

}

}

Nov 9, 2012 at 10:41 PM
Edited Nov 9, 2012 at 10:58 PM

duplicated..

Nov 9, 2012 at 10:41 PM

Hi,

After checking logs from last night, I saw that the line where it seemed to stop working was inside the SendData method of the SocketEx class, after the call to thisSent = client.Send(data, offset + sent, length - sent, SocketFlags.None);

Checking the documentation of the Socket class, it says

"If you are using a connection-oriented protocol, Send will block until all of the bytes in the buffer are sent."

"The time-out value, in milliseconds. If you set the property with a value between 1 and 499, the value will be changed to 500. The default value is 0, which indicates an infinite time-out period."

So I'm evaluating the possibility that maybe all my thread stopped there waiting for the data to be sent. I just set the SendTimeOut property of the server and now we are running the module again waiting to see if this solves the issue I had.

What do you think, is this possible? Maybe the send method of the socket [for one reason, maybe there was an issue sending the data] was just waiting there a confirmation that never finished.