Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my c# program not showing the bytes in textbox.. please help to find error


C#
private void button1_Click(object sender, EventArgs e)
       {
           sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
           IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse("192.168.0.177"), 80);
           textBox2.Text = localEndPoint.ToString();
           try
           {
               sck.Connect(localEndPoint);
               byte[] bytes = new byte[9600];


               
               string o = Encoding.UTF8.GetString(bytes);
               
               textBox1.Text = o;
               sck.Close();
           }
           catch
           {
               Console.Write("Unable to Connect \r\n");
               textBox1.Text = "error";
           }
           

       }
Posted
Updated 23-Nov-15 1:36am
v2
Comments
Gautham Prabhu K 23-Nov-15 7:52am    
I feel that you need to do enough research before posting a question.
The bug is very silly here if you read the API documentation you can find answer to this easily or even comparing with google or MSDN sample codes.
Savad.k.s 23-Nov-15 8:13am    
I know it is silly ... sorry about that. i am just a stater in programming world
Savad.k.s 23-Nov-15 8:15am    
sorry to ask.. but "int bytesRec = sender.Receive(bytes);" is there any way to change that int to string

You have to first receive some data, in order to show it. See the related MSDN code sample[^].
 
Share this answer
 
I am not seeing an socket read operation being done.
Please look at good example for Socket client in Google.
 
Share this answer
 

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

  Print Answers RSS


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