Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET
Hi All,
 
I am getting above error while reading the data (see marked bold in below code) from tcp client, though my 'Connect' and 'write' is working fine..what can be the issue..here is my client code Please help..
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.Net.Security;
using System.Timers;
 
namespace ClientRequest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                
                TcpClient tcpclnt = new TcpClient();
                Console.WriteLine("Connecting.....");
 
                IPAddress[] objLocalAddr = null;
                String strHostName = "";
                int port = 2425;
                
                strHostName = Dns.GetHostName();
                IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
                objLocalAddr = ipEntry.AddressList;
 
                tcpclnt.Connect(objLocalAddr[0], port);
             
 
                Console.WriteLine("Connected");
                Console.Write("Enter the string to be transmitted : ");
 
                String str = Console.ReadLine();
                Stream stm = tcpclnt.GetStream();
 
                ASCIIEncoding asen = new ASCIIEncoding();
                byte[] ba = asen.GetBytes(str);
                Console.WriteLine("Transmitting.....");
 
                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();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error..... " + e.StackTrace);
            }
        }
    }
}
Posted 15-Oct-12 22:47pm
Dipakm290
Edited 15-Oct-12 22:48pm
(no name)259.2K
v2

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

  Print Answers RSS
0 /\jmot 210
1 Richard Deeming 195
2 Richard MacCutchan 190
3 Zoltán Zörgő 175
4 Peter Leow 170
0 Sergey Alexandrovich Kryukov 9,328
1 OriginalGriff 6,831
2 Peter Leow 4,477
3 Zoltán Zörgő 3,984
4 Richard MacCutchan 2,832


Advertise | Privacy | Mobile
Web02 | 2.8.150129.1 | Last Updated 16 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100