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 6107529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:11:53+00:00 2026-05-23T14:11:53+00:00

I have a connection to IBM i (an AS/400) that communicates over a protocol/encoding

  • 0

I have a connection to IBM i (an AS/400) that communicates over a protocol/encoding called TN5250. I haven’t been able to match it against any of the encodings listed here; how can I convert this text to something I can use? UTF8, ASCII; anything in a Windows-friendly text format will do. It must not involve buying a third-party library.

Here’s some “working” code I found elsewhere. “address” is an IP address.

        Socket SocketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        System.Net.IPEndPoint remoteEndPoint = new System.Net.IPEndPoint(IPAddress.Parse("address"), 23);
        SocketClient.Connect(remoteEndPoint);
        byte[] buffer = new byte[10];
        textBox1.Text += Receive(SocketClient, buffer, 0, buffer.Length, 10000).Trim() + "\r\n";
    }
    public static string Receive(Socket socket, byte[] buffer, int offset, int size, int timeout)
    {
        int startTickCount = Environment.TickCount;
        int received = 0;  // how many bytes is already received
        do
        {
            if (Environment.TickCount > startTickCount + timeout)
                throw new Exception("Timeout.");
            try
            {
                received += socket.Receive(buffer, offset + received, size - received, SocketFlags.None);
                return Encoding.GetEncoding(37).GetString(buffer, 0, buffer.Length);
                //byte[] buf = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), Encoding.UTF8, buffer);
                //return Encoding.GetEncoding("IBM500").GetString(buf, 0, buffer.Length);
            }
            catch (SocketException ex)
            {
                if (ex.SocketErrorCode == SocketError.WouldBlock ||
                    ex.SocketErrorCode == SocketError.IOPending ||
                    ex.SocketErrorCode == SocketError.NoBufferSpaceAvailable)
                {
                    // socket buffer is probably empty, wait and try again
                    Thread.Sleep(30);
                }
                else
                    throw ex;  // any serious error occurr
            }
        } while (received < size);
        return "";
    }

This is a Telnet connection. Works fine in a Windows telnet window. The solution I really want is a way to capture the stdout from the telnet session, but apparently terminal programs like Telnet don’t write to stdout.

  • 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-23T14:11:54+00:00Added an answer on May 23, 2026 at 2:11 pm

    The TN5250J project is a working TN5250 client written in Java.

    TN5250 is the IBM protocol that rides on top of Telnet. It is intended for the IBM midrange family of ‘dumb’ green screen terminals. This family is block mode, meaning the host sends a full display panel out to the client in one transmission, and the client sends a full display panel back to the host in one single transmission. This, as opposed to a character-by-character transmission.

    As a very high level overview, the 5250 protocol describes how to format the display (start/stop field, field attributes like underline and colour) as well as what function keys are acceptable. The client needs to understand these formatting instructions in order to properly render the data coming from the host. Likewise, the client does not send back the full display panel including constants and formatting; instead, it sends back the input-capable fields.

    There is no stdout per se; the human readable display panel requires rendering by the client. You may get a good sense for the raw data by using Wireshark to capture the packets and comparing them to an actual TN5250 display showing the same transaction.

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

Sidebar

Related Questions

I'm hearing that is better to have one connection open upon app start up
I have a PPPOE connection on a computer. That computer has two LAN cards
IBM only provides a database connection to the iSeries, thus I have to work
I have a development project that requires us to be able to support informix
I have a connection to an access database that implements MSDataShape that works perfectly
I'm connecting to an IBM Websphere MQ. I want to be able to match
I have connection leak to DB in my code. The funny thing is that
We have developed a custom WCF channel which communicates via IBM Websphere MQ. We
I am reading excel file and for that I do have connection string in
I am trying to access database from a Class Library Project. I have connection

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.