1 | |
|
2 | |
|
3 | |
|
4 | |
package ca.uhn.hl7v2.protocol.impl; |
5 | |
|
6 | |
import java.io.IOException; |
7 | |
import java.net.Socket; |
8 | |
import java.net.SocketAddress; |
9 | |
|
10 | |
import ca.uhn.hl7v2.protocol.TransportException; |
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
public class ClientSocketStreamSource extends SocketStreamSource { |
19 | |
|
20 | |
private SocketAddress myAddress; |
21 | |
private Socket mySocket; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | 15 | public ClientSocketStreamSource(SocketAddress theAddress) throws TransportException { |
28 | 15 | myAddress = theAddress; |
29 | 15 | } |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public Socket getSocket() { |
35 | 145 | return mySocket; |
36 | |
} |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public void connect() throws TransportException { |
42 | 15 | mySocket = getSocket(myAddress); |
43 | 15 | } |
44 | |
|
45 | |
private Socket getSocket(SocketAddress theAddress) throws TransportException { |
46 | 15 | Socket s = new Socket(); |
47 | |
try { |
48 | 15 | s.connect(theAddress); |
49 | 0 | } catch (IOException e) { |
50 | 0 | throw new TransportException(e); |
51 | 15 | } |
52 | 15 | return s; |
53 | |
} |
54 | |
|
55 | |
} |