Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*; //contains the basics needed for network operations
- import java.io.*;
- import java.util.*;
- public class TCP_Echo_Client {
- public static void main(String[] args) throws IOException{
- //String host = "193.188.43.36";
- //String host = "tombaker-ict.research.um.edu.mt";
- String host ="10.249.45.5"; //Room 6 BLK B Lvl -1
- // String host = "10.64.16.146";
- byte[] response = new byte[100];
- //int port = 1024 + 7;
- int port = 7;
- Socket clientSock=null;
- try {
- InetAddress address = InetAddress.getByName(host);
- clientSock = new Socket(address, port);
- if (clientSock != null)
- System.out.println("SocketClient is connected");
- PrintStream outpStream = new PrintStream(clientSock.getOutputStream());
- BufferedInputStream binpStream = new BufferedInputStream(clientSock.
- getInputStream());
- String msg = "Hi there CIS 2103, Year 2015\\n";
- System.out.print("Message sent to the ECHO Server: " + msg);
- outpStream.println(msg); // to output stream to the server
- binpStream.read(response);
- System.out.print("Message received from the ECHO Server: ");
- String instr = "";
- for (int k = 0; k < response.length; k++)
- {char c = (char)response[k];
- if ((int) c!= 13)
- instr = instr + c;
- }
- System.out.println(instr);
- }
- catch (IOException f) {
- System.out.println("IOException: " + f);
- }
- catch (Exception g) {
- System.out.println("Exception: " + g);
- }
- finally { clientSock.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement