Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3599308
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:21:05+00:00 2026-05-18T20:21:05+00:00

Currently I am working on a network project which includes connecting to tcp servers

  • 0

Currently I am working on a network project which includes connecting to tcp servers and some devices. For a long time I successfully used below code for sending tcp command and receiving responses for some device models, but when I try it for Windows Telnet Server 2003 and a Fortigate device, even though I can build tcp connection successfully all I can get as response is some character set like ??%??????’????.

My function for receiving response is:

   private string receive()
    {
        StringBuilder sbReadBuffer = new StringBuilder();
        bool isFinished = false;
        NetworkStream ns = tcpClient.GetStream();
        DateTime lastConTime = DateTime.Now;

        while (!isFinished)
        {
            if (!ns.DataAvailable)
            {
                Thread.Sleep(200);

                if ((DateTime.Now - lastConTime).TotalSeconds > Prms.tcpSendReceiveTimeoutInSeconds)
                    break;
                else
                    continue;
            }

            Int32 receiveCount = ns.Read(receiveBuffer, 0, receiveBuffer.Length);
            String received = new ASCIIEncoding().GetString(receiveBuffer, 0, receiveCount);

            sbReadBuffer.Append(received);

            foreach (String terminaterToken in terminaterTokens)
                if (sbReadBuffer.ToString().EndsWith(terminaterToken))
                    isFinished = true;

            lastConTime = DateTime.Now;
        }

        return sbReadBuffer.ToString();
    }
}

and for building tcp connection and calling receive function:

        TcpClient tcpClient = new TcpClient()
    {
        SendTimeout = 10000,
        ReceiveTimeout = 10000
    };

    tcpClient.Connect(wanIp, 23);
    String initialMessage = receive();

I tested received messages for the devices that above code works without a problem and I realized for each different device model the initial response is always something like “??%??????’????” but it followed by logical responses like “welcome” vs.

During my tests I discovered the program connects to server/device successfully but can not receive valid responses, which I do not know why. Any idea about this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:21:06+00:00Added an answer on May 18, 2026 at 8:21 pm

    The problems causing “??%??” symbols is because of the telnet option IAC. Returning response values as IAC has bigger decimal codes than 255. Further information about IAC can be reached from the address

    support.microsoft.com/kb/231866

    The problem with IAC values is that when you try to parse the responses with C# tcpClient using standart code

                byte[] sendBuffer = new ASCIIEncoding().GetBytes(str + strNewLine);
                tcpClient.GetStream().Write(sendBuffer, 0, sendBuffer.Length);
    

    the code produces the above “??%” values when an IAC values received.

    To prevent this and handling IAC values I did some research and found an excellent telnet project on the address http://www.codeproject.com/KB/IP/TelnetSocket.aspx which perfectly handles the IAC values.

    For better understanding handling IAC values also checking MinimalisticTelnet library’s source code will be useful. I was able to get responses without a problem using MinimalisticTelnet but it failed on sending messages for the devices I work on so I preferred telnet socket project. But I strongly suggest to study MinimalisticTelnet source code for better understanding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The system I am currently working on requires some role-based security, which is well
I am currently working on a project and my goal is to locate text
I'm currently working on creating a new C# project that needs to interact with
I am currently working on a project with specific requirements. A brief overview of
I'm working on a application which is communicating by network to monitor another application's
I currently working on an issue tracker for my company to help them keep
I'm currently working at a small web development company, we mostly do campaign sites
The company I'm currently working for is using Selenium for Uniting-Testing our User Interface.
We are currently working in a private beta and so are still in the
I'm currently working on an internal sales application for the company I work for,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.