Mercurial > 510Connectbot
annotate src/org/tn5250j/framework/transport/SocketConnector.java @ 97:586b2eedb0d5
Added tag stable-1.8.0 for changeset 5e52fa030308
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 16 Jun 2014 18:02:30 -0700 |
parents | 33eb63352be5 |
children | 77ac18bc1b2f |
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 |
39 /** | |
40 * Creates a new instance that creates a plain socket by default. | |
41 */ | |
42 public SocketConnector() { | |
25
5949eb469a79
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
10
diff
changeset
|
43 |
3 | 44 } |
45 | |
46 /** | |
91
33eb63352be5
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
27
diff
changeset
|
47 * Create a new client Socket to the given destination, port and sslType of |
33eb63352be5
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
27
diff
changeset
|
48 * encryption. |
3 | 49 * @param destination |
50 * @param port | |
8 | 51 * @return a new client socket, or null if |
3 | 52 */ |
91
33eb63352be5
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
27
diff
changeset
|
53 public Socket createSocket(String destination, int port, String sslType, String homeDirectory, TerminalBridge bridge, TerminalManager manager) { |
3 | 54 |
55 Socket socket = null; | |
56 Exception ex = null; | |
8 | 57 |
58 if (sslType == null || sslType.trim().length() == 0 || | |
3 | 59 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
|
60 Log.i(TAG,"Creating Plain Socket"); |
3 | 61 try { |
62 // Use Socket Constructor!!! SocketFactory for jdk 1.4 | |
63 socket = new Socket(destination,port); | |
64 } catch (Exception e) { | |
65 ex = e; | |
66 } | |
67 } else { //SSL SOCKET | |
68 | |
26
9ae1c889a64c
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
25
diff
changeset
|
69 Log.i(TAG,"Creating SSL ["+sslType+"] Socket"); |
8 | 70 |
3 | 71 SSLInterface sslIf = null; |
8 | 72 |
3 | 73 try { |
10 | 74 sslIf = (SSLInterface) new SSLImplementation(bridge, manager); |
3 | 75 } catch (Exception e) { |
76 ex = new Exception("Failed to create SSLInterface Instance. " + | |
77 "Message is ["+e.getMessage()+"]"); | |
78 } | |
8 | 79 |
3 | 80 if (sslIf != null) { |
91
33eb63352be5
remove 5250 configuration
Carl Byington <carl@five-ten-sg.com>
parents:
27
diff
changeset
|
81 sslIf.init(sslType, homeDirectory); |
10 | 82 socket = sslIf.createSSLSocket(destination, port); |
3 | 83 } |
84 } | |
85 | |
86 if (ex != null) { | |
27
b29b39f386a4
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
26
diff
changeset
|
87 Log.e(TAG, "exception", ex); |
3 | 88 } |
89 if (socket == null) { | |
27
b29b39f386a4
adding tn5250 files, native android logging
Carl Byington <carl@five-ten-sg.com>
parents:
26
diff
changeset
|
90 Log.w(TAG, "No socket was created"); |
3 | 91 } |
92 return socket; | |
93 } | |
8 | 94 |
95 | |
3 | 96 } |