Ace
Sending text from ChatForm.cs to chathandler.cs to server does not work
server button code:
ChatHandler.cs
i have also skill issue with english ;-;
private void Sendpacket_Click(object sender, EventArgs e)
{
try
{
if (txtMessage.Text.Trim() != "")
{
ChatHandler.ClientToServer(txtMessage.Text);
AddMessage("Me", txtMessage.Text.Trim());
txtMessage.Text = "";
txtMessage.Focus();
}
}
private void Sendpacket_Click(object sender, EventArgs e)
{
try
{
if (txtMessage.Text.Trim() != "")
{
ChatHandler.ClientToServer(txtMessage.Text);
AddMessage("Me", txtMessage.Text.Trim());
txtMessage.Text = "";
txtMessage.Focus();
}
}
public class ChatHandler : IMessageProcessor
{
ISender sender;
public bool CanExecute(IMessage message) => message is DoChat || message is DoKillChatForm || message is DoStartChatForm;
public bool CanExecuteFrom(ISender sender) => true;
public void Execute(ISender sender, IMessage message)
{
switch (message)
{
case DoKillChatForm Msg:
closechat();
break;
case DoStartChatForm Msg:
startchat();
break;
case DoChat Msg:
OnDataReceived(Msg.PacketDms);
break;
}
}
public void ClientToServer(string message)
{
try
{
sender.Send(new GetChat { Message = message.ToString() });
}
catch (Exception ex)
{
MessageBox.Show($"Error sending message: {ex.Message}");
}
}
public class ChatHandler : IMessageProcessor
{
ISender sender;
public bool CanExecute(IMessage message) => message is DoChat || message is DoKillChatForm || message is DoStartChatForm;
public bool CanExecuteFrom(ISender sender) => true;
public void Execute(ISender sender, IMessage message)
{
switch (message)
{
case DoKillChatForm Msg:
closechat();
break;
case DoStartChatForm Msg:
startchat();
break;
case DoChat Msg:
OnDataReceived(Msg.PacketDms);
break;
}
}
public void ClientToServer(string message)
{
try
{
sender.Send(new GetChat { Message = message.ToString() });
}
catch (Exception ex)
{
MessageBox.Show($"Error sending message: {ex.Message}");
}
}
2 replies