private async Task Connect() { var req = new RequestConnect(); req.SessionId = sid; try { using (var call = client.Connect(req)) { while (await call.ResponseStream.MoveNext()) { var stream = call.ResponseStream.Current; if (stream.Join != null) { Debug.Log("join : " + stream.Join.Name); } else if (stream.Leave != null) { Debug.Log("leave : " + stream.Leave.Name); } else if (stream.Log != null) { Debug.Log("Say :" + stream.Log.Name + " - " + stream.Log.Message); recvMsg = stream.Log.Name + " - " + stream.Log.Message; } } Debug.Log("server accepted your leave signal"); } } catch (RpcException e) { Debug.Log(ExceptionMsg(e)); } channel.ShutdownAsync().Wait(); channel = null; }
// Atiende solicitud de conexion enviada por el formulario. static private void RealizarConexion(RequestConnect req) { Log.WriteEntry(ClassName, "RealizarConexion", TraceEventType.Verbose, "Recibiendo solicitud de conexion del formulario."); // Desconectando conexion existente if (null != _zyanConn) { if (_zyanConn.IsSessionValid) { // Cerrando conexion previa. _zyanConn.Dispose(); } } RealizarConexion(req.ServerUrl); }
/* Describes a common handlers */ #region Common handlers /// <summary> /// User was connected /// </summary> public void HConnect(TcpMessage request) { string name = request.From; IPEndPoint tcpEP = null, udpEP = null; try { tcpEP = RequestConnect.GetRemotePoint(request); udpEP = RequestConnect.GetUdpRemotePoint(request); } catch { Msg("Wrong message format"); // Cannot answer to client because info about listener's socket is broken return; } // We should check if he in client list (it will be an error) if (Users.ContainsValue(tcpEP)) { string realName = Users.GetKey(tcpEP); string cause = "Connection: user " + name + " already connected as " + realName; SendRequest(tcpEP, new ResponseConnect(false, cause).GetBytes()); Msg(cause); return; } // and has unique name (answer Cancel) if (Users.ContainsKey(name)) { string cause = "Connection: username " + name + " is not available"; SendRequest(tcpEP, new ResponseConnect(false, cause).GetBytes()); Msg(cause); return; } SendRequest(tcpEP, new ResponseConnect(true, "OK").GetBytes()); Users.Add(name, new UserInfo(tcpEP, udpEP.Port)); Msg("User " + name + " [" + tcpEP.ToString() + "] added in user list"); if (OnUserState != null) { OnUserState(name, UserState.UserLogIn); } SendBroadcast(new ResponseUser(name, UserState.UserLogIn)); }
void OnConnectRequest(RequestConnect rc) { _viewModel.Servers.Add(new ServerViewModel(rc.Name, rc.ConnectionString)); }