comparison app/src/main/java/org/tn5250j/framework/transport/SocketConnector.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/org/tn5250j/framework/transport/SocketConnector.java@77ac18bc1b2f
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
1
2 /**
3 * @(#)SocketConnector.java
4 * @author Stephen M. Kennedy
5 *
6 * Copyright: Copyright (c) 2001
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this software; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 * Boston, MA 02111-1307 USA
22 *
23 */
24 package org.tn5250j.framework.transport;
25
26 import java.net.Socket;
27
28 import com.five_ten_sg.connectbot.service.TerminalBridge;
29 import com.five_ten_sg.connectbot.service.TerminalManager;
30
31 import org.tn5250j.framework.transport.SSL.SSLImplementation;
32 import org.tn5250j.TN5250jConstants;
33 import android.util.Log;
34
35
36 public class SocketConnector {
37 private static final String TAG = "SocketConnector";
38
39 /**
40 * Creates a new instance that creates a plain socket by default.
41 */
42 public SocketConnector() {
43 }
44
45 /**
46 * Create a new client Socket to the given destination, port and sslType of
47 * encryption.
48 * @param destination
49 * @param port
50 * @return a new client socket, or null if
51 */
52 public Socket createSocket(String destination, int port, String sslType, String homeDirectory, TerminalBridge bridge, TerminalManager manager) {
53 Socket socket = null;
54 Exception ex = null;
55
56 if (sslType == null || sslType.trim().length() == 0 ||
57 sslType.toUpperCase().equals(TN5250jConstants.SSL_TYPE_NONE)) {
58 Log.i(TAG, "Creating Plain Socket");
59
60 try {
61 // Use Socket Constructor!!! SocketFactory for jdk 1.4
62 socket = new Socket(destination, port);
63 }
64 catch (Exception e) {
65 ex = e;
66 }
67 }
68 else { //SSL SOCKET
69 Log.i(TAG, "Creating SSL [" + sslType + "] Socket");
70 SSLInterface sslIf = null;
71
72 try {
73 sslIf = (SSLInterface) new SSLImplementation(bridge, manager);
74 }
75 catch (Exception e) {
76 ex = new Exception("Failed to create SSLInterface Instance. " +
77 "Message is [" + e.getMessage() + "]");
78 }
79
80 if (sslIf != null) {
81 sslIf.init(sslType, homeDirectory);
82 socket = sslIf.createSSLSocket(destination, port);
83 }
84 }
85
86 if (ex != null) {
87 Log.e(TAG, "exception", ex);
88 }
89
90 if (socket == null) {
91 Log.w(TAG, "No socket was created");
92 }
93
94 return socket;
95 }
96
97
98 }