Forum Discussion
I have a problem that i cant solve it
i want to write a program that pass data(message) from one ip to another.
you can see my code below and the error is:
Only one usage of each socket address (protocol/network address/port) is normally permitted
TcpListener listerner = new TcpListener(44444);
TcpClient client;
String message="";
Object tts;
Socket m_clientSocket;
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
listerner.Start();
Timer1.Enabled = true;
TextBox4.Enabled = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
if (TextBox1.Text == "" | TextBox2.Text == "" | TextBox3.Text == "")
{
Label1.Text = "Sorry Uncomplete data";
}
else
{
client = new TcpClient(TextBox2.Text, 44444);
StreamWriter writer = new StreamWriter(client.GetStream());
writer.Write(TextBox1.Text + " says:" + TextBox3.Text);
writer.Flush();
TextBox3.Text = "";
}
}
catch (Exception ex)
{
listerner.Stop();
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
try
{
if (listerner.Pending())
{
message = "";
client = listerner.AcceptTcpClient();
StreamReader reader = new StreamReader(client.GetStream());
while (reader.Peek() > -1)
{
message = message + Convert.ToChar(reader.Read()).ToString();
}
this.Focus();
TextBox4.Text = (TextBox4.Text + message + "\n");
SpVoice s = new SpVoice();
s.Speak(message);
}
}
catch
{
listerner.Stop();
}
}
Related Content
- 3 months ago
- 8 years ago
Recent Discussions
- 22 hours ago
- 2 days ago