Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernize socketTest #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
build
target/
6 changes: 3 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

<target name="compile">
<mkdir dir="${build.dir}"/>
<javac srcdir="src/" destdir="${build.dir}" optimize="on" debug="off">
<javac srcdir="src/main/java" destdir="${build.dir}" optimize="on" debug="off">
<include name="**/*.java"/>
</javac>
<copy todir="${build.dir}/" overwrite="yes">
<fileset dir="src/">
<fileset dir="src/main/java">
<include name="*.txt"/>
</fileset>
</copy>
<copy todir="${build.dir}/icons" overwrite="yes">
<fileset dir="src/icons">
<fileset dir="src/main/resources/icons">
<include name="*.gif"/>
</fileset>
</copy>
Expand Down
4 changes: 4 additions & 0 deletions compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

mvn clean install
mvn dependency:copy-dependencies
3 changes: 3 additions & 0 deletions execute
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

$JAVA_HOME/bin/java -cp target/SocketTest-3.0-SNAPSHOT.jar:target/dependency/* net.sf.sockettest.SocketTest
Binary file removed lib/metouia.jar
Binary file not shown.
Binary file removed lib/swt-awt-win32-3111.dll
Binary file not shown.
Binary file removed lib/swt-win32-3111.dll
Binary file not shown.
Binary file removed lib/swt.jar
Binary file not shown.
1,041 changes: 0 additions & 1,041 deletions nbproject/build-impl.xml

This file was deleted.

8 changes: 0 additions & 8 deletions nbproject/genfiles.properties

This file was deleted.

Binary file removed nbproject/private/cache/.refactorit/cache.bin
Binary file not shown.
Empty file.
9 changes: 0 additions & 9 deletions nbproject/private/private.properties

This file was deleted.

4 changes: 0 additions & 4 deletions nbproject/private/private.xml

This file was deleted.

85 changes: 0 additions & 85 deletions nbproject/project.properties

This file was deleted.

15 changes: 0 additions & 15 deletions nbproject/project.xml

This file was deleted.

49 changes: 49 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>net.sf.sockettest</groupId>
<artifactId>SocketTest</artifactId>
<version>3.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>SocketTest</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- mvn install:install-file -Dfile=dist/metouia.jar -DgroupId=net.sf.metouia -DartifactId=metouia -Dversion=1.0.0 -Dpackaging=jar -->
<dependency>
<groupId>net.sf.metouia</groupId>
<artifactId>metouia</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package net.sf.sockettest;

import net.sf.sockettest.swing.AskView;

import javax.net.ssl.*;
import java.security.cert.*;
import java.awt.*;
import javax.swing.*;
import java.security.*;

Expand All @@ -13,13 +14,13 @@
*/
public class MyTrustManager implements X509TrustManager {

private Component parentComponent;
private AskView view;
private X509TrustManager sunJSSEX509TrustManager;



public MyTrustManager(Component parentComponent) throws Exception {
this.parentComponent = parentComponent;
public MyTrustManager(AskView view) throws Exception {
this.view = view;

TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509", "SunJSSE");

Expand Down Expand Up @@ -84,13 +85,9 @@ public void checkServerTrusted(X509Certificate[] chain, String authType)
} else {
sb.append("\n Issued By:\n \t"+chain[i].getSubjectDN());
}
}

int option = JOptionPane.showConfirmDialog(parentComponent,
sb.toString(), "Certificate Confirmation",
JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
};

if(option==JOptionPane.NO_OPTION) {
if(view.confirm("Certificate Confirmation", sb.toString(), JOptionPane.NO_OPTION)) {
throw new CertificateException("Not Trusted Certificate!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,52 @@

import java.net.*;
import java.io.*;
import net.sf.sockettest.swing.SocketTestClient;

import net.sf.sockettest.controller.SocketTestClientController;
import net.sf.sockettest.swing.SocketTestClientView;
import org.apache.commons.lang3.StringEscapeUtils;

import javax.xml.bind.DatatypeConverter;

/**
*
* @author Akshathkumar Shetty
*/
public class SocketClient extends Thread {

private static SocketClient socketClient=null;
private SocketTestClientController controller;
private Socket socket=null;
private SocketTestClient parent;
private SocketTestClientView view;
private BufferedInputStream in;
private boolean desonnected=false;
private boolean disconnected =false;

public synchronized void setDesonnected(boolean cr) {
desonnected=cr;
public synchronized void setDisconnected(boolean cr) {
disconnected =cr;
}

private SocketClient(SocketTestClient parent, Socket s) {
private SocketClient(SocketTestClientView view, SocketTestClientController controller, Socket s) {
super("SocketClient");
this.parent = parent;
this.view = view;
this.controller = controller;
socket=s;
setDesonnected(false);
setDisconnected(false);
start();
}

public static synchronized SocketClient handle(SocketTestClient parent, Socket s) {
public static synchronized SocketClient handle(SocketTestClientView view, SocketTestClientController controller, Socket s) {
if(socketClient==null)
socketClient=new SocketClient(parent, s);
socketClient=new SocketClient(view, controller, s);
else {
if(socketClient.socket!=null) {
try {
socketClient.socket.close();
} catch (Exception e) {
parent.error(e.getMessage());
view.error(e.getMessage());
}
}
socketClient.socket=null;
socketClient=new SocketClient(parent,s);
socketClient=new SocketClient(view, controller, s);
}
return socketClient;
}
Expand All @@ -55,38 +63,36 @@ public void run() {
} catch(IOException e2) {
System.err.println("Socket not closed :"+e2);
}
parent.error("Could not open socket : "+e.getMessage());
parent.disconnect();
view.error("Could not open socket : "+e.getMessage());
controller.disconnect();
return;
}

while(!desonnected) {
while(!disconnected) {
try {
String got = readInputStream(in); //in.readLine();
String got = readInputStream(in);
if(got==null) {
//parent.error("Connection closed by client");
parent.disconnect();
controller.disconnect();
break;
}
//got = got.replaceAll("\n","<LF>");
//got = got.replaceAll("\r","<CR>");
//parent.append("R: "+got);
parent.appendnoNewLine(got);
if(view.isHexOutput()) {
got = DatatypeConverter.printHexBinary(got.getBytes());
}
view.appendMessage(got);
} catch(IOException e) {
if(!desonnected) {
parent.error(e.getMessage(),"Connection lost");
parent.disconnect();
if(!disconnected) {
view.error(e.getMessage(),"Connection lost");
controller.disconnect();
}
break;
}
}//end of while
}
try {
is.close();
in.close();
//socket.close();
} catch (Exception err) {}
socket=null;
}//end of run
}

private static String readInputStream(BufferedInputStream _in) throws IOException {
String data = "";
Expand All @@ -101,7 +107,6 @@ private static String readInputStream(BufferedInputStream _in) throws IOExceptio
_in.read(byteData);
data += new String(byteData);
}
return data;
return StringEscapeUtils.unescapeJava(data);
}

}
Loading