CHAT

MOUSER 24/03/2016 22:28:13
#459888
Interessante a colocação Kerp, vou dar uma pesquisada melhor, andar um pouco mais, fiz o teste do Socket e deu certo, mas como você mesmo diz, com a analogia do carteiro, como o aplicativo é atual, está em desenvolvimento agora, começar a pesquisar sobre o WebAPI, como vou usar o projeto a longo prazo, mas sem fins lucrativos e pequeno, vou pesquisar tambem um servidor para desenvolver o projeto e aplicar tudo diretamente, depois que estiver tudo pronto, vou começar a desenvolver o chat literalmente. Com socket vi que funciona, mas estou vendo futuros erros com o tempo. Vou fazer isso Kerp. Eu conheço as maquinas que tenho em mãos, mas não conheço as maquinas dos meus amigos. Se souberem de algum servidor on line 24hrs gratuitos para fazer esses tipos de projetos, eu agradeço, vou pesquisar isso e também pesquisar sobre WebAPI voltado para o CHAT, vou dar uma estudada no seu conteúdo no canal também Kerp.
MOUSER 24/03/2016 22:35:04
#459889
Join Chat Room Front
<asp:Panel Runat=[Ô]server[Ô] ID=[Ô]pnlLogin[Ô] HorizontalAlign=[Ô]Center[Ô]
style=[Ô]margin-left: 2px[Ô] Width=[Ô]405px[Ô]>
<fieldset>
<p class=[Ô]style10[Ô]>Login Section</p>


<br />
<br />


Please enter the name you'd like to be reffered to as!</td>


<br />


User Name :

<asp:TextBox ID=[Ô]txtUserName[Ô] Runat=[Ô]server[Ô] CssClass=[Ô]style8[Ô]></asp:TextBox>
<br class=[Ô]style8[Ô] />
<asp:RequiredFieldValidator ID=[Ô]req1[Ô] Runat=[Ô]server[Ô]
ControlToValidate=[Ô]txtUserName[Ô] CssClass=[Ô]style8[Ô] Display=[Ô]Dynamic[Ô]
ErrorMessage=[Ô]Please Check Back[Ô]></asp:RequiredFieldValidator>

<br />

<br />
<br />

<asp:Button cssclass=[Ô]btn[Ô] id=[Ô]btnLogin[Ô] Runat=[Ô]server[Ô] Text=[Ô]LOGIN[Ô]
OnClick=[Ô]btnLogin_Click[Ô]
style=[Ô]font-family: [ô]Century Gothic[ô]; font-size: medium[Ô]></asp:Button>

<br />

</fieldset><br />  </asp:Panel>



<asp:Panel Runat=[Ô]server[Ô] ID=[Ô]pnlChat[Ô] Height=[Ô]249px[Ô] Width=[Ô]399px[Ô]>
<fieldset style=[Ô]width: 401px; height: 270px[Ô]>
<p class=[Ô]style10[Ô]>Selection Section</p>
<div class=[Ô]style12[Ô]>
<span><span class=[Ô]style17[Ô]>
<br />
         Please Select the Rooms your interested in joining.</span></span><span
class=[Ô]style15[Ô]><span class=[Ô]style8[Ô]><br /> </span></span>
<span class=[Ô]style13[Ô]><span class=[Ô]style16[Ô]><span class=[Ô]style14[Ô]>
                                                                                                    
</span></span><span class=[Ô]style8[Ô]><span class=[Ô]style15[Ô]>
<br />
</span><span class=[Ô]style16[Ô]><span class=[Ô]style14[Ô]> Available Rooms:</span></span></span></span><span
class=[Ô]style8[Ô]>          </span>
<asp:ListBox ID=[Ô]lstRooms[Ô] runat=[Ô]server[Ô] CssClass=[Ô]style8[Ô]>
<asp:ListItem Selected=[Ô]True[Ô] Text=[Ô]Toys[Ô] Value=[Ô]1[Ô]>Toys</asp:ListItem>
<asp:ListItem Text=[Ô]Movies[Ô] Value=[Ô]2[Ô]>Movies</asp:ListItem>
<asp:ListItem Text=[Ô]Other[Ô] Value=[Ô]3[Ô]>Other</asp:ListItem>
</asp:ListBox>
<br />
<br />
                                      
<asp:Button ID=[Ô]btnChat[Ô] Runat=[Ô]server[Ô] CssClass=[Ô]btn[Ô] OnClick=[Ô]btnChat_Click[Ô]

style=[Ô]font-family: [ô]Century Gothic[ô]; font-size: medium; text-align: justify;[Ô] Text=[Ô]Join[Ô]
Width=[Ô]64px[Ô] />
<br />
<br />
<br />
<br />
<br />
</div>
</fieldset>
</asp:Panel>




Backend

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
string uname;

protected void Page_Load(object sender, EventArgs e)
{
string hold = DateTime.Today.ToShortDateString();

if (Session[[Ô]uname[Ô]] == null)
{
Response.Redirect([Ô]sorry.aspx?page2=current[Ô]);

}
else
{

uname = Session[[Ô]uname[Ô]].ToString();
}
if (Session[[Ô]UserName[Ô]]!=null)
{
pnlLogin.Visible = false;
pnlChat.Visible = true;
Disclaimer.Visible = false;
}
else
{
Disclaimer.Visible = true;
pnlLogin.Visible = false;
pnlChat.Visible = false;

}
}

protected void btnLogin_Click(object sender, System.EventArgs e)
{
Session[[Ô]UserName[Ô]]=txtUserName.Text;
pnlLogin.Visible=false;
pnlChat.Visible=true;
Disclaimer.Visible = false;
}


protected void btnChat_Click(object sender, System.EventArgs e)
{
Session[[Ô]title[Ô]] = this.lstRooms.SelectedItem.ToString();
Response.Redirect([Ô]Chat.aspx?rid=[Ô] + lstRooms.SelectedValue);
}

protected void exit_Click(object sender, System.EventArgs e)
{
Response.Redirect([Ô]defautl.aspx[Ô]);
}

protected void enter_Click(object sender, System.EventArgs e)
{
pnlLogin.Visible = true;
pnlChat.Visible = false;
Disclaimer.Visible = false;
}
}




Chat Room front end code

<table cellpadding=[Ô]0[Ô] cellspacing=[Ô]0[Ô]>
<tr>
<td class=[Ô]style3[Ô]></span></td>
<td width=[Ô]70%[Ô]>
<asp:textbox runat=[Ô]server[Ô] TextMode=[Ô]MultiLine[Ô] id=[Ô]txt[Ô] rows=[Ô]16[Ô]
Columns=[Ô]79[Ô] Width=[Ô]506px[Ô] CssClass=[Ô]style12[Ô] ReadOnly=[Ô]true[Ô] ></asp:textbox>
<span class=[Ô]style12[Ô]> 
<i>
<br />
</i>
</span>
<asp:TextBox id=[Ô]txtMsg[Ô] Width=[Ô]400[Ô] Runat=[Ô]server[Ô] CssClass=[Ô]style12[Ô]></asp:TextBox>
<span class=[Ô]style12[Ô]>   </span>
<input id=[Ô]btn[Ô]
onclick=[Ô]button_clicked()[Ô] type=[Ô]button[Ô] value=[Ô]SEND[Ô] class=[Ô]style12[Ô]/><span
class=[Ô]style12[Ô]>
</td>
<td width=[Ô]20%[Ô] rowspan=[Ô]2[Ô] valign=[Ô]top[Ô]>
<span class=[Ô]style12[Ô]>Room Members <i> <br />
 

</span>

</i></span>

<asp:ListBox runat=[Ô]server[Ô] Width=[Ô]125px[Ô] ID=[Ô]lstMembers[Ô]
Enabled=[Ô]false[Ô] Height=[Ô]226px[Ô] CssClass=[Ô]style12[Ô]></asp:ListBox>

</td>
<td width=[Ô]10%[Ô] class=[Ô]style12[Ô]> </td>
</tr>
</table>


Back End page
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using ASPNETChat;
using System.Web.Script.Services;
using System.Web.Script;
using System.Collections;
using System.Collections.Generic;

public partial class Chat : System.Web.UI.Page
{

string uname;

protected void Page_Load(object sender, EventArgs e)
{

string hold = DateTime.Today.ToShortDateString();

if (Session[[Ô]uname[Ô]] == null || (Session[[Ô]userid[Ô]] == null))
{
Response.Redirect([Ô]sorry.aspx?page2=current[Ô]);

}
else
{

uname = Session[[Ô]uname[Ô]].ToString();
}


if (Session[[Ô]UserName[Ô]] == null)
Response.Redirect([Ô]Default.aspx[Ô]);
if (string.IsNullOrEmpty(Request.QueryString[[Ô]rid[Ô]]))
Response.Redirect([Ô]Default.aspx[Ô]);

txtMsg.Attributes.Add([Ô]onkeypress[Ô], [Ô]return clickButton(event,[ô]btn[ô])[Ô]);
if (!IsPostBack)
{
hdnRoomID.Value = Request.QueryString[[Ô]rid[Ô]];
ChatRoom room = ChatEngine.GetRoom(hdnRoomID.Value);
string prevMsgs = room.JoinRoom(Session[[Ô]UserName[Ô]].ToString(), Session[[Ô]UserName[Ô]].ToString());
txt.Text = prevMsgs;
foreach (string s in room.GetRoomUsersNames())
{
lstMembers.Items.Add(new ListItem(s, s));
}

}

this.Label1.Text = Session[[Ô]title[Ô]].ToString();
}


#region Script Callback functions

/// <summary>
/// This function is called from the client script
/// </summary>
/// <param name=[Ô]msg[Ô]></param>
/// <param name=[Ô]roomID[Ô]></param>
/// <returns></returns>
[WebMethod]
static public string SendMessage(string msg, string roomID)
{
try
{
ChatRoom room = ChatEngine.GetRoom(roomID);
string res = [Ô][Ô];
if (room != null)
{
res = room.SendMessage(msg, HttpContext.Current.Session[[Ô]UserName[Ô]].ToString());
}
return res;
}
catch (Exception ex)
{

}
return [Ô][Ô];
}


/// <summary>
/// This function is called peridical
MOUSER 24/03/2016 22:37:00
#459890
called from the user to update the messages
/// </summary>
/// <param name=[Ô]otherUserID[Ô]></param>
/// <returns></returns>
[WebMethod]
static public string UpdateUser(string roomID)
{
try
{
ChatRoom room = ChatEngine.GetRoom(roomID);
if (room != null)
{
string res = [Ô][Ô];
if (room != null)
{
res = room.UpdateUser(HttpContext.Current.Session[[Ô]UserName[Ô]].ToString());
}
return res;
}
}
catch (Exception ex)
{

}
return [Ô][Ô];
}


/// <summary>
/// This function is called from the client when the user is about to leave the room
/// </summary>
/// <param name=[Ô]otherUser[Ô]></param>
/// <returns></returns>
[WebMethod]
static public string LeaveRoom(string roomID)
{
try
{
ChatRoom room = ChatEngine.GetRoom(roomID);
if (room != null)
room.LeaveRoom(HttpContext.Current.Session[[Ô]UserName[Ô]].ToString());
}
catch (Exception ex)
{

}
return [Ô][Ô];
}


/// <summary>
/// Returns a comma separated string containing the names of the users currently online
/// </summary>
/// <param name=[Ô]roomID[Ô]></param>
/// <returns></returns>
[WebMethod]
static public string UpdateRoomMembers(string roomID)
{
try
{
ChatRoom room = ChatEngine.GetRoom(roomID);
if (room != null)
{
IEnumerable<string> users = room.GetRoomUsersNames();
string res = [Ô][Ô];

foreach (string s in users)
{
res += s + [Ô],[Ô];
}
return res;
}
}
catch (Exception ex)
{
}
return [Ô][Ô];
}
#endregion

protected void LinkButton1_Click(object sender, EventArgs e)
{
if (Session[[Ô]acc[Ô]].ToString() == [Ô][Ô])
{
Response.Redirect([Ô]login.aspx[Ô]);
}

else if (Session[[Ô]acc[Ô]].ToString() == [Ô]2[Ô])
{
Response.Redirect([Ô]catagorylist.aspx[Ô]);
}

else if (Session[[Ô]acc[Ô]].ToString() == [Ô]3[Ô] || (Session[[Ô]acc[Ô]].ToString() == [Ô]4[Ô]))
{
Response.Redirect([Ô]maintance.aspx[Ô]);
}
}
}
MOUSER 24/03/2016 22:39:03
#459891
Eu encontrei esse codigo acima em C#, vale a pena dar uma estudada?

KERPLUNK 24/03/2016 22:47:09
#459892
Se você quer um chat web(em WebForms, baseado em Session que não é confiável) vale...
MOUSER 24/03/2016 23:02:09
#459893
Voltar a pesquisar mais! Ainda não é o que procuro então, trabalhar com seções e correr o risco de ter uma seção encerrada inesperadamente, o que o torna não muito confiável para um chat.
KERPLUNK 24/03/2016 23:06:49
#459894
Já te dei o caminho das pedras. Faça uma WebAPI e um client(web ou desktop, você quem sabe) e consuma
MOUSER 25/03/2016 18:42:17
#459914
Sim, isso que farei, WebAPI + Client Desktop.
MOUSER 26/03/2016 11:06:45
#459925
Galera, só peço um pouco de desculpa pela minha falta de informação em WEBAPI, já encontrei muito conteúdo interessante. Mas aceito sugestões também para estudar também. (Não quero código fonte, quero desenvolver o meu próprio, mas quero conhecer as ferramentas que podem me auxiliar nesse projeto). Agradecer a todos até agora.
KERPLUNK 26/03/2016 23:19:23
#459940
No meu canal tem bastante coisa, incluindo como consumir.
Página 3 de 5 [45 registro(s)]
Tópico encerrado , respostas não são mais permitidas