Repository navigation
Expand file tree
/
Copy pathInfoClient.java
More file actions
58 lines (55 loc) · 1.93 KB
/
Copy pathInfoClient.java
File metadata and controls
58 lines (55 loc) · 1.93 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
FileName: InfoClient.java
Authors
kamugisha maurice 10/U/9243/PS 210015398
karamagi phillip 10/U/15599/PS 210021293
lubega mark 10/U/1806/PS 210000411
mukasa samuel 10/U/9337/PS 210007604
mutungi stephen 10/U/9352/PS 210007639
semakula kraiba 10/U/9446/PS 210006461
ziwa ali 10/U/9477/PS 210006468
niwagaba aaron 09/U/12306/PS 209008071
*/
/*
FileName: Searchfile.java
Authors
kamugisha maurice 10/U/9243/PS 210015398
karamagi phillip 10/U/15599/PS 210021293
lubega mark 10/U/1806/PS 210000411
mukasa samuel 10/U/9337/PS 210007604
mutungi stephen 10/U/9352/PS 210007639
semakula kraiba 10/U/9446/PS 210006461
ziwa ali 10/U/9477/PS 210006468
niwagaba aaron 09/U/12306/PS 209008071
*/
import java.net.*;
import java.io.*;
import java.util.*;
public class InfoClient
{
public static void main(String [] args)
{ //declare variables
String msg;
String serverName = args[0];
Scanner red = new Scanner(System.in);
int port = Integer.parseInt(args[1]);
try
{ //client connection to server
System.out.println("Connecting to " + serverName + " on port " + port);
Socket client = new Socket(serverName, port);
//output if connection is established
System.out.println("Just connected to "+ client.getRemoteSocketAddress());
OutputStream outToServer = client.getOutputStream(); // store commands to server in variable
DataOutputStream out = new DataOutputStream(outToServer);
msg = red.nextLine();
out.writeUTF(msg);
InputStream inFromServer = client.getInputStream();//get replys from server
DataInputStream in = new DataInputStream(inFromServer);
System.out.println("Server reply: " + in.readUTF());//output server reply to client
client.close(); //close client
}catch(IOException e)//catch IOException
{
e.printStackTrace();
}
}
}