Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,53 @@
package com.hyperskill.database.clientside;

import com.google.gson.*;
import java.io.*;

import java.net.*;
import java.util.Scanner;


public class Client {
public static void main(String[] args) {
System.out.println("Hello World!");
JsonParser obj = new JsonParser();
System.out.println(obj);
public static void main(String[] args) {
System.out.println("Client started!");

String address = "127.0.0.1";
int port = 23456;
DataInputStream input = null;
DataOutputStream output = null;
try{
Socket socket = new Socket(InetAddress.getByName(address), port);
input = new DataInputStream(socket.getInputStream());
output = new DataOutputStream(socket.getOutputStream());
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

/*Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();

int index = 0;

String s = str.substring(str.indexOf("#")+2);
index = Integer.parseInt(s);
System.out.println(index);
*/
try {
output.writeUTF("Give me a record # 12");
} catch (IOException e) {
e.printStackTrace();
}

System.out.println("Sent: " + " Give me a record # 12");

try {

System.out.println("Recieved: " + input.readUTF());
}catch (IOException e) {
e.printStackTrace();
}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,50 @@




import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println("Server started!");
String address = "127.0.0.1";
int port = 23456;

Socket socket = null;
DataInputStream input = null;
DataOutputStream output = null;
try {
ServerSocket server = new ServerSocket(port, 50, InetAddress.getByName(address));
socket = server.accept();
input = new DataInputStream(socket.getInputStream());
output = new DataOutputStream(socket.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}

String ask = null;
try {
ask = input.readUTF();
System.out.println("Recieved: " + ask);
} catch (IOException e) {
e.printStackTrace();
}

String str = null;

try {
str = "A record # 12 was sent!";
System.out.println("Sent: " + str);
output.writeUTF(str);
} catch (IOException e) {
e.printStackTrace();
}


}
}