@@ -109,40 +109,45 @@ dependencies {
109
109
## Quickstart
110
110
111
111
``` java
112
+ package com.ngrok.quickstart ;
113
+
112
114
import com.ngrok.Session ;
113
- import com.ngrok.HttpTunnel ;
114
-
115
- public class Echo {
116
- public static void main (String [] args ) throws IOException {
117
- // Session.withAuthtokenFromEnv() will create a new session builder, pulling NGROK_AUTHTOKEN env variable.
118
- // You can get your authtoken by registering at https://dashboard.ngrok.com
119
- var sessionBuilder = Session . withAuthtokenFromEnv(). metadata(" my session" );
120
- // Session.Builder let you customize different aspects of the session, see docs for details.
121
- // After customizing the builder, you connect:
122
- try (var session = sessionBuilder. connect()) {
123
- // Creates and configures http listener that will be using oauth to secure it
124
- var listenerBuilder = session. httpEndpoint(). metadata(" my listener" )
125
- .oauth(new Http .OAuthOptions (" google" )));
126
- // Now start listening with the above configuration
127
- try (var listener = listenerBuilder. listen()) {
128
- System . out. println(" ngrok url: " + listener. getUrl());
129
- var buf = ByteBuffer . allocateDirect(1024 );
130
-
131
- while (true ) {
132
- // Accept a new connection
133
- var conn = listener. accept();
134
-
135
- // Read from the connection
136
- conn. read(buf);
137
-
138
- System . out. println(buf. asCharBuffer());
139
-
140
- // Or write to it
141
- conn. write(buf);
115
+ import com.ngrok.Http ;
116
+
117
+ import java.io.IOException ;
118
+ import java.nio.ByteBuffer ;
119
+
120
+ public class Quickstart {
121
+ public static void main (String [] args ) throws IOException {
122
+ // Session.withAuthtokenFromEnv() will create a new session builder, pulling NGROK_AUTHTOKEN env variable.
123
+ // You can get your authtoken by registering at https://dashboard.ngrok.com
124
+ var sessionBuilder = Session . withAuthtokenFromEnv(). metadata(" my session" );
125
+ // Session.Builder let you customize different aspects of the session, see docs for details.
126
+ // After customizing the builder, you connect:
127
+ try (var session = sessionBuilder. connect()) {
128
+ // Creates and configures http listener that will be using oauth to secure it
129
+ var listenerBuilder = session. httpEndpoint(). metadata(" my listener" )
130
+ .oauthOptions(new Http .OAuth (" google" ));
131
+ // Now start listening with the above configuration
132
+ try (var listener = listenerBuilder. listen()) {
133
+ System . out. println(" ngrok url: " + listener. getUrl());
134
+ var buf = ByteBuffer . allocateDirect(1024 );
135
+
136
+ while (true ) {
137
+ // Accept a new connection
138
+ var conn = listener. accept();
139
+
140
+ // Read from the connection
141
+ conn. read(buf);
142
+
143
+ System . out. println(buf. asCharBuffer());
144
+
145
+ // Or write to it
146
+ conn. write(buf);
147
+ }
142
148
}
143
- }
144
- }
145
- }
149
+ }
150
+ }
146
151
}
147
152
```
148
153
0 commit comments