Socketimpl for TN3270
Hi, I am trying to use Java for some 3270 (IBM mainframe) data streaming but the plain (default) socket functionality Java seems to provide does not support this type of protocol (is actually 3270 over Telnet, i.e. TN3270).
My question is, if I want to write my own socket implementation (sub-class SocketImpl) to support TN3270, can this only be done via native (C/C++) implementations for this class (in a DLL) or are there any lower level Java classes/implementations available I can use to achieve this?
[517 byte] By [
OzBoka] at [2007-10-3 5:16:30]

That's not how you would do it. You would subclass Socket, or you would write your own TN3270InputStream and TN3270OutputStream. You'll find a basis for this in any number of open-source Java Telnet implementations.
ejpa at 2007-7-14 23:23:09 >

From what I can see that is not going to work as the TN3270 handshaking (agreeing on actual 3270 protocol, i.e. whether using TN3270E or default) happens as part of connecting which is native code in net.dll...
How do I override this by using my own input/output streams? I need to provide an override for connect really don't I (at connect stage I don't have a input/output stream yet)?
OzBoka at 2007-7-14 23:23:09 >

If the server speaks TCP/IP you don't have a connect/handshake problem as it is defined by TCP/IP and completely implemented miles below anything you can get your hands on.
Any application-protocol-level handshake can be done in Java.
If the server doesn't speak TCP/IP you've got a much bigger problem ...
ejpa at 2007-7-14 23:23:09 >

> Hi, I am trying to use Java for some 3270 (IBM
> mainframe) data streaming but the plain (default)
> socket functionality Java seems to provide does not
> support this type of protocol (is actually 3270 over
> Telnet, i.e. TN3270).
My question is, if I want to
> write my own socket implementation (sub-class
> SocketImpl) to support TN3270, can this only be done
> via native (C/C++) implementations for this class (in
> a DLL) or are there any lower level Java
> classes/implementations available I can use to
> achieve this?
Telnet is implemented on top of TCP/IP.
And java sockets do not do telnet. They (sockets) don't do any other protocol that runs on TCP/IP either.
The fact that 3270 is slightly modified doesn't mean that it does anything special for TCP/IP. It means that it is modifying the telnet protocol, which again, runs on top of TCP.
See the following which describes specifically that the protocol runs on top of TCP/IP (search for "what is TN3270" - 3rd find)
http://www.cisco.com/univercd/cc/td/doc/cisintwk/dsgngde/tn3270/tndg_c1.htm
So one can definitely use java sockets to implement it. It does however require additional code.
It might be easier to start with a telnet library and modify it. Or perhaps just find a library that already does it.
Thanks Jschell, I'll have a look around.
The one thing that is still throwing me and that I don't understand is that as part of creating an instance of the socket class in my console app (using the host IP address and (telnet) port 23), as stated by the Java API documentation, the socket tries to connect to the specified host. Now, I'm not sure whether the following behaviour is expected, but as part of this connection process, the host (IBM mainframe) prompts me for the protocol, i.e. are sending me IAC DO TN3270E commands to which I need to respond accordingly - I need to override the default socket class functionality to intercept and respond to these (socket class does nothing with these commands). How do I go about doing this without my own SocketImpl class?
OzBoka at 2007-7-14 23:23:09 >

You use the socket input stream and output stream to receive and send Telnet commands including IAC.
ejpa at 2007-7-14 23:23:09 >

> Thanks Jschell, I'll have a look around.
The one
> thing that is still throwing me and that I don't
> understand is that as part of creating an instance of
> the socket class in my console app (using the host IP
> address and (telnet) port 23), as stated by the Java
> API documentation, the socket tries to connect to the
> specified host. Now, I'm not sure whether the
> following behaviour is expected, but as part of this
> connection process, the host (IBM mainframe) prompts
> me for the protocol, i.e. are sending me IAC DO
> TN3270E commands to which I need to respond
> accordingly - I need to override the default socket
> class functionality to intercept and respond to these
> (socket class does nothing with these commands). How
> do I go about doing this without my own SocketImpl
> class?
Sockets send messages. Sockets receive messages. You don't need to change the socket to get this behavior - it already does it.
The mainframe is sending you a message. It expects a response to that message. Code that uses a socket (uses not replaces) can handle this.
