C
C#11mo ago
Ace

Sending text from ChatForm.cs to chathandler.cs to server does not work

server button code:
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();
}
}
ChatHandler.cs
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}");
}
}
i have also skill issue with english ;-;
1 Reply
Anchy
Anchy11mo ago
what do you mean "does not work", what are you expecting to happen? what are you observing?
Want results from more Discord servers?
Add your server