-
Notifications
You must be signed in to change notification settings - Fork 0
/
RTPTestClient.java
44 lines (36 loc) · 1.48 KB
/
RTPTestClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.net.*;
public class RTPTestClient {
public static void main(String[] args) {
System.out.println("Beginning RTPTestClient");
// RTPSocket s1 = new RTPSocket();
int serverPort = Integer.parseInt(args[0]);
int bindPort = 0;
byte[] helloWorldData = "Hello World!".getBytes();
byte[] foobarData = "FOObar World!".getBytes();
InetSocketAddress bindsource = null;
InetSocketAddress destination = null;
try {
bindPort = RTPSocket.getEphemeralPort(InetAddress.getLocalHost());
bindsource = new InetSocketAddress("0.0.0.0" , bindPort);
destination = new InetSocketAddress("localhost", serverPort);
} catch (Exception e) {
System.out.println("Was unable to get ephemeral port and create source address");
}
if (bindsource != null){
System.out.println("Going to try to connect to " + serverPort + " from " + bindPort);
RTPSocket clientRTPSocket = new RTPSocket(new InetSocketAddress("localhost", serverPort));
System.out.println("Connecting...");
boolean connection = clientRTPSocket.connect(destination);
System.out.println("Connection success:" + connection);
System.out.println(clientRTPSocket.toString());
if (connection){
System.out.println("Trying to send \"Hello World!\"");
clientRTPSocket.send(helloWorldData);
System.out.println("Trying to send \"FOObar World!\"");
clientRTPSocket.send(foobarData);
String toasty = new String(clientRTPSocket.receive());
System.out.println("toasty:" + toasty);
}
}
}
}