You are viewing our Forum Archives. To view or take place in current topics click here.
Am I helpful!
YES
100.00% (2 votes)
100.00% (2 votes)
Not really!
0.00% (0 votes)
0.00% (0 votes)
Didn't respond in 24hours
0.00% (0 votes)
0.00% (0 votes)
Total Votes: 2
C#|Help/Tutorials|taking requests|CLOSED
Posted:
C#|Help/Tutorials|taking requests|CLOSEDPosted:
Status: Offline
Joined: Jun 24, 201311Year Member
Posts: 50
Reputation Power: 1
Status: Offline
Joined: Jun 24, 201311Year Member
Posts: 50
Reputation Power: 1
Welcome to my C# Help/Tutorial Request Post!
Info:
I am taking requests to help people with c# problems Hopefully I can help!
I will respond to almost all posts!
Status:Done
Don't Forget //comments are helpful
Ask Away!
Last edited by -Icon-remix- ; edited 7 times in total
#2. Posted:
Status: Offline
Joined: Jun 24, 201311Year Member
Posts: 50
Reputation Power: 1
Status: Offline
Joined: Jun 24, 201311Year Member
Posts: 50
Reputation Power: 1
The_Modzpop wrote Ok so im making a chat program and cant seem to get the text to come out right this is what happens when I text to myself
[ Register or Signin to view external links. ]
how do I make it so it does not say the system window thing?
heres what I have
the tool works but it just bothers me that I cant fix the text. thanks in advance.namespace Client_Chat
{
public partial class Form1 : Form
{
Socket sck;
EndPoint epLocal, epRemote;
public Form1()
{
InitializeComponent();
sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
textLocalIp.Text = GetLocalIP();
textFriendsIp.Text = GetLocalIP();
}
private string GetLocalIP()
{
IPHostEntry host;
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
return "192.168.1.7";
}
private void MessageCallBack(IAsyncResult aResult)
{
try
{
int size = sck.EndReceiveFrom(aResult, ref epRemote);
if (size > 0)
{
byte[] receivedData = new byte[1464];
receivedData = (byte[])aResult.AsyncState;
ASCIIEncoding eEncoding = new ASCIIEncoding();
string receivedMessage = eEncoding.GetString(receivedData);
listBox1.Items.Add("Client 2: "+receivedMessage);
}
byte[] buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString());
}
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show("Welcome To Client Chat Express!");
MessageBox.Show("Have A Great Experence Talking To Your Friends And Famley Or Coworkers!");
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void tabPage1_Click(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void textFriendsIp_TextChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
try
{
epLocal = new IPEndPoint(IPAddress.Parse(textLocalIp.Text), Convert.ToInt32(textLocalPort.Text));
sck.Bind(epLocal);
epRemote = new IPEndPoint(IPAddress.Parse(textFriendsIp.Text), Convert.ToInt32(textFriendsPort.Text));
sck.Connect(epRemote);
byte[] buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
button4.Text = "Send Message";
button4.Enabled = false;
button4.Enabled = true;
textsendmessage.Focus();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
MessageBox.Show("You Are Connected To Client Chat!");
}
private void button4_Click(object sender, EventArgs e)
{
try
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
byte[] msg = new byte[1500];
msg = enc.GetBytes(textsendmessage.Text);
sck.Send(msg);
listBox1.Items.Add("You:" +textsendmessage);
textsendmessage.Clear();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
also ik my code is not neat but im still a bit new so bare with me.
private void button4_Click(object sender, EventArgs e)
{
try
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
byte[] msg = new byte[1500];
msg = enc.GetBytes(textsendmessage.Text);
sck.Send(msg);
listBox1.Items.Add("You:" + textsendmessage.Text);
textsendmessage.Clear();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Replace this with button4_click and see what happens I hope I helped! And remember Thanks help!
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.