Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b0566e6

Browse files
server test
1 parent 4d8b4b4 commit b0566e6

File tree

3 files changed

+41
-22
lines changed

3 files changed

+41
-22
lines changed

‎src/com/company/MyClient.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.company;
2+
3+
4+
import java.io.*;
5+
import java.net.*;
6+
7+
public class MyClient {
8+
public static void main(String[] args) {
9+
10+
try{
11+
Socket s=new Socket("localhost",6666);
12+
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
13+
dout.writeUTF("Hello Server");
14+
dout.flush();
15+
dout.close();
16+
s.close();
17+
}catch(Exception e){System.out.println(e);}
18+
}
19+
}

‎src/com/company/Myserver.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.company;
2+
3+
import java.io.DataInputStream;
4+
import java.net.ServerSocket;
5+
import java.net.Socket;
6+
7+
public class Myserver {
8+
public static void main(String[] args) {
9+
try{
10+
ServerSocket ss=new ServerSocket(6666);
11+
Socket s=ss.accept();//establishes connection
12+
DataInputStream dis=new DataInputStream(s.getInputStream());
13+
String str=(String)dis.readUTF();
14+
System.out.println("message= "+str);
15+
ss.close();
16+
}catch(Exception e){System.out.println(e);}
17+
}
18+
}

‎src/com/company/apicall.java‎

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
11
package com.company;
22

3-
public class apicall {
4-
public static void main(String[] args) {
53

64

7-
// Host url
8-
String host = "https://movie-database-imdb-alternative.p.rapidapi.com/";
9-
String charset = "UTF-8";
10-
// Headers for a request
11-
String x_rapidapi_host = "movie-database-imdb-alternative.p.rapidapi.com";
12-
String x_rapidapi_key = <YOUR_RAPIDAPI_KEY>;//Type here your key
13-
// Params
14-
String s = "Pulp";
15-
// Format query for preventing encoding problems
16-
String query = String.format("s=%s",
17-
URLEncoder.encode(s, charset));
185

6+
public class apicall {
7+
public static void main(String[] args) {
8+
System.out.println("api call");
199

2010

21-
HttpResponse <JsonNode> response = Unirest.get(host + "?" + query)
22-
.header("x-rapidapi-host", x_rapidapi_host)
23-
.header("x-rapidapi-key", x_rapidapi_key)
24-
.asJson();
25-
System.out.println(response.getStatus());
26-
System.out.println(response.getHeaders().get("Content-Type"));
2711
}
28-
29-
30-
}
12+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /