really need you help .
my project is to connect two PC's via cable and use the tcp socket send the string in the client text box form to the server. the problem is thati can just send one string then the connection will close.
client code(c#):of course in the try catch way :
String str = textBox2.Text;
Stream stm = tcpclnt.GetStream();
ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(str);
textBox1.Text="Sending...";
stm.Write(ba,0,ba.Length);
byte[] bb = new byte[100];
int k = stm.Read(bb,0,100);
for (int i = 0;i < k; i++)
{
Console.Write(Convert.ToChar(bb[i]));
}
tcpclnt.Close();
//////////////
the server code :also in the try catch way :
int k = 0;
byte[] b = new byte[100];
for (; ; )
{
for (int i = 0; i < 100000; i++)
{ }
k = s.Receive(b);
MessageBox.Show(k + "");
textBox1.Text = "Recieved...";
for (int i = 0; i < k; i++)
{
textBox2.Text = textBox2.Text + Convert.ToChar(b[i]);
}
MessageBox.Show(k + "");
ASCIIEncoding asen = new ASCIIEncoding();
s.Send(asen.GetBytes("Automatic message:" + "String received by server!"));
textBox1.Text = "\n Automatic message sent!";
MessageBox.Show(k + "");
s.Close();
}
my question is : can i make a loop in the server to send not just one string ,i need to send many string without close the connection .?
note : the client and server every one will be executed after the button in each form pressed.
note : the connection on some port will be establish and succeed in the form load .