Mercurial > 510Connectbot
annotate src/org/tn5250j/framework/transport/SocketConnector.java @ 63:07c7055cc124 tn5250
add 5250 config entries
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 13 Jun 2014 15:35:46 -0700 |
parents | b29b39f386a4 |
children | 33eb63352be5 |
rev | line source |
---|---|
3 | 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 | |
10 | 28 import com.five_ten_sg.connectbot.service.TerminalBridge; |
29 import com.five_ten_sg.connectbot.service.TerminalManager; | |
30 | |
8 | 31 import org.tn5250j.framework.transport.SSL.SSLImplementation; |
3 | 32 import org.tn5250j.TN5250jConstants; |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
33 import android.util.Log; |
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
34 |
3 | 35 |
36 public class SocketConnector { | |
26
9ae1c889a64c
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
25
diff
changeset
|
37 private static final String TAG = "SocketConnector"; |
3 | 38 String sslType = null; |
39 | |
40 /** | |
41 * Creates a new instance that creates a plain socket by default. | |
42 */ | |
43 public SocketConnector() { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
44 |
3 | 45 } |
46 | |
47 /** | |
48 * Set the type of SSL connection to use. Specify null or an empty string | |
8 | 49 * to use a plain socket. |
3 | 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 | |
8 | 60 * a plain socket will be created. Otherwise, a new SSL socket of the |
3 | 61 * specified type will be created. |
62 * @param destination | |
63 * @param port | |
8 | 64 * @return a new client socket, or null if |
3 | 65 */ |
10 | 66 public Socket createSocket(String destination, int port, TerminalBridge bridge, TerminalManager manager) { |
3 | 67 |
68 Socket socket = null; | |
69 Exception ex = null; | |
8 | 70 |
71 if (sslType == null || sslType.trim().length() == 0 || | |
3 | 72 sslType.toUpperCase().equals(TN5250jConstants.SSL_TYPE_NONE)) { |
26
9ae1c889a64c
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
25
diff
changeset
|
73 Log.i(TAG,"Creating Plain Socket"); |
3 | 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 | |
26
9ae1c889a64c
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
25
diff
changeset
|
82 Log.i(TAG,"Creating SSL ["+sslType+"] Socket"); |
8 | 83 |
3 | 84 SSLInterface sslIf = null; |
8 | 85 |
3 | 86 try { |
10 | 87 sslIf = (SSLInterface) new SSLImplementation(bridge, manager); |
3 | 88 } catch (Exception e) { |
89 ex = new Exception("Failed to create SSLInterface Instance. " + | |
90 "Message is ["+e.getMessage()+"]"); | |
91 } | |
8 | 92 |
3 | 93 if (sslIf != null) { |
94 sslIf.init(sslType); | |
10 | 95 socket = sslIf.createSSLSocket(destination, port); |
3 | 96 } |
97 } | |
98 | |
99 if (ex != null) { | |
27
b29b39f386a4
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
26
diff
changeset
|
100 Log.e(TAG, "exception", ex); |
3 | 101 } |
102 if (socket == null) { | |
27
b29b39f386a4
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
26
diff
changeset
|
103 Log.w(TAG, "No socket was created"); |
3 | 104 } |
105 return socket; | |
106 } | |
8 | 107 |
108 | |
3 | 109 } |