Skip to content

Commit

Permalink
Add UnNegotiateTelnet Function
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Downarowicz committed Mar 1, 2022
1 parent 78a746a commit 08d8317
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.downardo</groupId>
<artifactId>j3270Server</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>
<name>Java 3270 Server</name>
<packaging>jar</packaging>
<description>This libary allows the user to write servers for IBM 3270 Terminal emulators.</description>
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/at/downardo/j3270Server/Telnet.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,46 @@ public class Telnet {
private static final byte TERMINALTYPE = (byte)0x18;
private static final byte EOR = (byte)0x19;

/**
* UnNegotiateTelnet will naively (e.g. not checking client responses) attempt
* to restore the telnet options state to what it was before NegotiateTelnet()
* was called.
* @param out
* @param in
*/
public static void UnNegotiateTelnet(BufferedOutputStream out, BufferedInputStream in) {
byte[] _trash = new byte[255];
byte[] _t = {IAC,WONT,EOR,IAC,WONT,BINARY};

try {
out.write(_t);
out.flush();
in.read(_trash);

byte[] _2t = {IAC,DONT,BINARY};
out.write(_2t);
out.flush();

in.read(_trash);

byte[] _3t = {IAC,DONT,EOR};

out.write(_3t);
out.flush();

in.read(_trash);

byte[] _4t = {IAC,DONT,TERMINALTYPE};

out.write(_4t);
out.flush();

in.read(_trash);

} catch (IOException e) {
e.printStackTrace();
}
}


/**
Expand Down

0 comments on commit 08d8317

Please sign in to comment.