FVVSBN
پنج شنبه 02 دی 1389, 12:20 عصر
سلام
من
این کد مشکلش کجاست؟
ارسال میکنه ولی دریافت نمیکنه
publicpartialclassFormClient : Form1
{
UdpClient udpClient;
Thread newThread;
UnicodeEncoding uniCodeEncoding = newUnicodeEncoding();
bool ChattingStatus = false;
public FormClient()
{
InitializeComponent();
udpClient = newUdpClient();
newThread = newThread(newThreadStart(ClientListener));
newThread.Start();
}
void ClientListener()
{
while (ChattingStatus)
{
IPEndPoint ipep;
if (txtIP.Text.Trim() != "")
{
ipep = newIPEndPoint(IPAddress.Parse(txtIP.Text.Trim()), 3977);
}
else
{
ipep = null;
}
byte[] byteReciver = udpClient.Receive(ref ipep);
toolStripStatusLabel1.Text = "Reciver\tCalculating";
txtRecivedMessage.Text += "\r\n" + uniCodeEncoding.GetString(byteReciver);
toolStripStatusLabel1.Text = "Recived";
}
}
privatevoid btnSendMessage_Click(object sender, EventArgs e)
{
byte[] byteSender = uniCodeEncoding.GetBytes(txtSendMessage.Text);
IPEndPoint ipep = newIPEndPoint(IPAddress.Parse(txtIP.Text.Trim()), 3977);
udpClient.Send(byteSender, byteSender.Length,ipep);
ChattingStatus = true;
toolStripStatusLabel1.Text = "Sent";
txtSendMessage.Clear();
txtSendMessage.Focus();
}
privatevoid txtSendMessage_TextChanged(object sender, EventArgs e)
{
if (txtSendMessage.Text.Length > 0 )
{
btnSendMessage.Enabled = true;
}
else
{
btnSendMessage.Enabled = false;
}
}
privatevoid txtSendMessage_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && btnSendMessage.Enabled == true)
{
btnSendMessage_Click(null, null);
}
}
privatevoid FormClient_FormClosing(object sender, FormClosingEventArgs e)
{
udpClient.Close();
}
privatevoid exitToolStripMenuItem_Click(object sender, EventArgs e)
{
FormClient_FormClosing(null, null);
}
}
من
این کد مشکلش کجاست؟
ارسال میکنه ولی دریافت نمیکنه
publicpartialclassFormClient : Form1
{
UdpClient udpClient;
Thread newThread;
UnicodeEncoding uniCodeEncoding = newUnicodeEncoding();
bool ChattingStatus = false;
public FormClient()
{
InitializeComponent();
udpClient = newUdpClient();
newThread = newThread(newThreadStart(ClientListener));
newThread.Start();
}
void ClientListener()
{
while (ChattingStatus)
{
IPEndPoint ipep;
if (txtIP.Text.Trim() != "")
{
ipep = newIPEndPoint(IPAddress.Parse(txtIP.Text.Trim()), 3977);
}
else
{
ipep = null;
}
byte[] byteReciver = udpClient.Receive(ref ipep);
toolStripStatusLabel1.Text = "Reciver\tCalculating";
txtRecivedMessage.Text += "\r\n" + uniCodeEncoding.GetString(byteReciver);
toolStripStatusLabel1.Text = "Recived";
}
}
privatevoid btnSendMessage_Click(object sender, EventArgs e)
{
byte[] byteSender = uniCodeEncoding.GetBytes(txtSendMessage.Text);
IPEndPoint ipep = newIPEndPoint(IPAddress.Parse(txtIP.Text.Trim()), 3977);
udpClient.Send(byteSender, byteSender.Length,ipep);
ChattingStatus = true;
toolStripStatusLabel1.Text = "Sent";
txtSendMessage.Clear();
txtSendMessage.Focus();
}
privatevoid txtSendMessage_TextChanged(object sender, EventArgs e)
{
if (txtSendMessage.Text.Length > 0 )
{
btnSendMessage.Enabled = true;
}
else
{
btnSendMessage.Enabled = false;
}
}
privatevoid txtSendMessage_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && btnSendMessage.Enabled == true)
{
btnSendMessage_Click(null, null);
}
}
privatevoid FormClient_FormClosing(object sender, FormClosingEventArgs e)
{
udpClient.Close();
}
privatevoid exitToolStripMenuItem_Click(object sender, EventArgs e)
{
FormClient_FormClosing(null, null);
}
}