Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I run my server succsessfully but when i prints data which i previously printed in console screen to address me what is going on , i want to display all that on text box , but it does not display, and when i close connection from client it displays all that information. why it happens .?

Here is my code ;

C#
public void GetData()
 {
   Form1 f = new Form1();
   string ipadd = getip();

   IPAddress ipAd = IPAddress.Parse("192.168.0.15"); //use local m/c IP   address, and use the same in the client
   // IPAddress ip = IPAddress.Parse(ipadd);
   txtip.Text = ipAd.ToString();
   txtport.Text = "3030";
   /* Initializes the Listener */
   TcpListener myList = new TcpListener(ipAd, 3030);

   /* Start Listeneting at the specified port */

   myList.Start();

   txtdata.Text = "The server is running at port 3030...";
   txtdata.Text = txtdata.Text + Environment.NewLine + "The local End point  is :" + myList.LocalEndpoint;
   txtdata.Text = txtdata.Text + Environment.NewLine + "Waiting for a   connection.....";



   Socket s = myList.AcceptSocket();

    txtdata.Text = txtdata.Text + Environment.NewLine +"Connection accepted from " + s.RemoteEndPoint;
   // txtdata.Text = "Connection accepted from " + s.RemoteEndPoint;

   }


Look at the code above when i write data on console it works but the same i want to print on txtdata (textbox) but it doesn't print , till connection close by client.
Posted
Updated 17-Jun-15 21:26pm
v3

1 solution

You should run the communication part in a background thread and use the invoke method to update the Form. See Updating Your Form from Another Thread without Creating Delegates for Every Type of Update[^].
 
Share this answer
 
Comments
Member 11543226 18-Jun-15 5:11am    
Now this all running but server accepts data for one time from client , however the same program accept data for multiple times in console app.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900