Mercurial > 510Connectbot
comparison src/org/tn5250j/framework/transport/SocketConnector.java @ 79:01d939969b10
merge tn5250 branch into default
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 16 Jun 2014 08:24:00 -0700 |
parents | b29b39f386a4 |
children | 33eb63352be5 |
comparison
equal
deleted
inserted
replaced
19:b3d0d806cbe2 | 79:01d939969b10 |
---|---|
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 String sslType = null; | |
39 | |
40 /** | |
41 * Creates a new instance that creates a plain socket by default. | |
42 */ | |
43 public SocketConnector() { | |
44 | |
45 } | |
46 | |
47 /** | |
48 * Set the type of SSL connection to use. Specify null or an empty string | |
49 * to use a plain socket. | |
50 * @param type The SSL connection type | |
51 * @see org.tn5250j.framework.transport.SSLConstants | |
52 */ | |
53 public void setSSLType(String type) { | |
54 sslType = type; | |
55 } | |
56 | |
57 /** | |
58 * Create a new client Socket to the given destination and port. If an SSL | |
59 * socket type has not been specified <i>(by setSSLType(String))</i>, then | |
60 * a plain socket will be created. Otherwise, a new SSL socket of the | |
61 * specified type will be created. | |
62 * @param destination | |
63 * @param port | |
64 * @return a new client socket, or null if | |
65 */ | |
66 public Socket createSocket(String destination, int port, TerminalBridge bridge, TerminalManager manager) { | |
67 | |
68 Socket socket = null; | |
69 Exception ex = null; | |
70 | |
71 if (sslType == null || sslType.trim().length() == 0 || | |
72 sslType.toUpperCase().equals(TN5250jConstants.SSL_TYPE_NONE)) { | |
73 Log.i(TAG,"Creating Plain Socket"); | |
74 try { | |
75 // Use Socket Constructor!!! SocketFactory for jdk 1.4 | |
76 socket = new Socket(destination,port); | |
77 } catch (Exception e) { | |
78 ex = e; | |
79 } | |
80 } else { //SSL SOCKET | |
81 | |
82 Log.i(TAG,"Creating SSL ["+sslType+"] Socket"); | |
83 | |
84 SSLInterface sslIf = null; | |
85 | |
86 try { | |
87 sslIf = (SSLInterface) new SSLImplementation(bridge, manager); | |
88 } catch (Exception e) { | |
89 ex = new Exception("Failed to create SSLInterface Instance. " + | |
90 "Message is ["+e.getMessage()+"]"); | |
91 } | |
92 | |
93 if (sslIf != null) { | |
94 sslIf.init(sslType); | |
95 socket = sslIf.createSSLSocket(destination, port); | |
96 } | |
97 } | |
98 | |
99 if (ex != null) { | |
100 Log.e(TAG, "exception", ex); | |
101 } | |
102 if (socket == null) { | |
103 Log.w(TAG, "No socket was created"); | |
104 } | |
105 return socket; | |
106 } | |
107 | |
108 | |
109 } |