Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #OS LAB1/5 made by Fensa08
- import java.io.BufferedReader;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.Socket;
- import java.io.BufferedReader;
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.net.ServerSocket;
- import java.net.Socket;
- public class TCPClient {
- public static void main(String []args) throws IOException {
- Socket s = new Socket("localhost", 9875);
- DataOutputStream out = new DataOutputStream(s.getOutputStream());
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- int i = 0;
- String line = in.readLine();
- String pom[] = line.split(" ");
- while(i < 4){
- if( i == 0){
- double x = Double.parseDouble(pom[0]);
- out.writeDouble(x);
- i++;
- }
- if( i == 1){
- long x = Long.parseLong(pom[1]);
- out.writeLong(x);
- i++;
- }
- if( i == 2){
- boolean x = Boolean.parseBoolean(pom[2]);
- out.writeBoolean(x);
- i++;
- }
- if(i == 3){
- out.writeUTF(pom[3]);
- i++;
- }
- }
- out.close();
- s.close();
- System.out.println("\n\n End of connection");
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------------
- public class TCPServer {
- public static void main(String []args) throws IOException {
- ServerSocket s = new ServerSocket(9875);
- Socket socket = s.accept();
- System.out.println("Connected");
- DataInputStream in = new DataInputStream(socket.getInputStream());
- //BufferedReader br = new BufferedReader()
- double a = 0;
- long b = 0;
- boolean c = false;
- String input = null;
- int i = 0;
- while(i < 4){
- if( i == 0){
- a = in.readDouble();
- i++;
- }
- if( i == 1){
- b = in.readLong();
- i++;
- }
- if( i == 2){
- c = in.readBoolean();
- i++;
- }
- if(i == 3){
- input = in.readUTF();
- i++;
- }
- }
- System.out.println(a + " "+b + " "+c + " "+input + " ");
- s.close();
- socket.close();
- System.out.println("\n\nClient has terminated the connection");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement