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
17 changes: 17 additions & 0 deletions 1. URL/URLClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.net.URL;

public class URLClass {

public static void main(String args[]) {
try {
URL url = new URL(
"https://www.google.co.in/search?sxsrf=ACYBGNTlCg6stXRWj6XfKxNBgxecqLRJiQ%3A1572264736726&source=hp&ei=INu2XfvqKYPzvAT4ho_oAQ&q=go&oq=go&gs_l=psy-ab.3..35i39l2j0i131l3j0l5.19302.19387..19663...0.0..0.125.239.0j2......0....1..gws-wiz.9sac5rg-3P0&ved=0ahUKEwj7-v3I9r7lAhWDOY8KHXjDAx0Q4dUDCAY&uact=5");
System.out.println(url.getProtocol());
System.out.println(url.getHost());
System.out.println(url.getPort());
System.out.println(url.getFile());
} catch (Exception e) {
System.out.println(e);
}
}
}
19 changes: 0 additions & 19 deletions 1. URL/URLclass.java

This file was deleted.

29 changes: 0 additions & 29 deletions 10. Two Way Communication using TCP/TcpClient.java

This file was deleted.

32 changes: 0 additions & 32 deletions 10. Two Way Communication using TCP/TcpServer.java

This file was deleted.

29 changes: 29 additions & 0 deletions 10. Two Way Communication using TCP/TwoWayTcpClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;
import java.util.Scanner;

public class TwoWayTcpClient {

public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
Socket s = new Socket("localhost", 5656);
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
DataInputStream dis = new DataInputStream(s.getInputStream());
while (true) {
System.out.println("Write Your message");
String str = scan.nextLine();
dout.writeUTF(str);
dout.flush();
if (str.equals("bye")) {
dout.close();
s.close();
break;
}
String str1 = (String) dis.readUTF();
System.out.println("Server Messaged--->" + str1);


}
}
}
32 changes: 32 additions & 0 deletions 10. Two Way Communication using TCP/TwoWayTcpServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class TwoWayTcpServer {

public static void main(String[] args) throws Exception {
ServerSocket ss = new ServerSocket(5656);
Socket s = ss.accept();
Scanner scan = new Scanner(System.in);
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
DataInputStream dis = new DataInputStream(s.getInputStream());
while (true) {
String str = dis.readUTF();
System.out.println("Client--->" + str);
if (str.equals("bye")) {
System.out.println("Client Messaged .... BYE..Exiting");
dis.close();
s.close();
ss.close();
break;
}
System.out.println("Enter your message:");
String str1 = scan.nextLine();
dout.writeUTF(str1);
dout.flush();
}

}
}
53 changes: 27 additions & 26 deletions 11. Two Way Communication Local/MyClient.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import java.net.*;
import java.io.*;
import java.util.*;
public class MyClient{
public static void main(String[] args)throws Exception{
Socket s=new Socket("192.168.43.153",6666);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
DataInputStream din=new DataInputStream(s.getInputStream());
Scanner scan=new Scanner(System.in);
while(true)
{
System.out.println("Enter Your message.");
String str=scan.nextLine();
dout.writeUTF(str);
dout.flush();
if(str.equals("bye"))
{
dout.close();
s.close();
break;
}
String str1=(String)din.readUTF();
System.out.println("Server--->"+str1);

}
}
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;
import java.util.Scanner;

public class MyClient {

public static void main(String[] args) throws Exception {
Socket s = new Socket("192.168.43.153", 6666);
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
DataInputStream din = new DataInputStream(s.getInputStream());
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("Enter Your message.");
String str = scan.nextLine();
dout.writeUTF(str);
dout.flush();
if (str.equals("bye")) {
dout.close();
s.close();
break;
}
String str1 = (String) din.readUTF();
System.out.println("Server--->" + str1);

}
}
}
61 changes: 31 additions & 30 deletions 11. Two Way Communication Local/MyServer.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import java.net.*;
import java.io.*;
import java.util.*;
public class MyServer{
public static void main(String[] args) throws Exception
{
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();
DataInputStream dis=new DataInputStream(s.getInputStream());
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
Scanner scan=new Scanner(System.in);
while(true)
{
String str=(String)dis.readUTF();
System.out.println("Client--->"+str);
if(str.equals("bye"))
{
System.out.println("Client Said Bye exiting");
dis.close();
dout.close();
s.close();
ss.close();
break;
}
System.out.println("Enter Your Message");
String str1=scan.nextLine();
dout.writeUTF(str1);
dout.flush();
}
}
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class MyServer {

public static void main(String[] args) throws Exception {
ServerSocket ss = new ServerSocket(6666);
Socket s = ss.accept();
DataInputStream dis = new DataInputStream(s.getInputStream());
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
Scanner scan = new Scanner(System.in);
while (true) {
String str = dis.readUTF();
System.out.println("Client--->" + str);
if (str.equals("bye")) {
System.out.println("Client Said Bye exiting");
dis.close();
dout.close();
s.close();
ss.close();
break;
}
System.out.println("Enter Your Message");
String str1 = scan.nextLine();
dout.writeUTF(str1);
dout.flush();
}
}
}
56 changes: 28 additions & 28 deletions 12. Multithreaded Server/Client.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import java.io.*;
import java.net.*;
import java.util.*;
public class Client{
public static void main(String[] args) throws Exception
{
Socket s=new Socket("localhost",6666);
DataOutputStream dout= new DataOutputStream(s.getOutputStream());
DataInputStream din=new DataInputStream(s.getInputStream());
Scanner scan=new Scanner(System.in);
while(true)
{
String strrecived=din.readUTF();
System.out.println("Server Messaged:"+strrecived);
System.out.println("Write Your Message");
String strtosend=scan.nextLine();
dout.writeUTF(strtosend);
dout.flush();
if(strtosend.equals("Exit"))
{
System.out.println("Client "+s+" is exiting");
s.close();
din.close();
dout.close();
break;
}
}
}
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {

public static void main(String[] args) throws Exception {
Socket s = new Socket("localhost", 6666);
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
DataInputStream din = new DataInputStream(s.getInputStream());
Scanner scan = new Scanner(System.in);
while (true) {
String strrecived = din.readUTF();
System.out.println("Server Messaged:" + strrecived);
System.out.println("Write Your Message");
String strtosend = scan.nextLine();
dout.writeUTF(strtosend);
dout.flush();
if (strtosend.equals("Exit")) {
System.out.println("Client " + s + " is exiting");
s.close();
din.close();
dout.close();
break;
}
}
}
}
43 changes: 43 additions & 0 deletions 12. Multithreaded Server/ClientHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;

/**
* @author Deki on 03.10.2020
* @project Networking_In_Java
**/
public class ClientHandler extends Thread {

Socket s;
DataInputStream dis;
DataOutputStream dout;
String strrecieved = "", strsent = "", name;

public ClientHandler(Socket s, String name, DataInputStream dis, DataOutputStream dout) {
this.s = s;
this.dis = dis;
this.dout = dout;
this.name = name;
}

@Override
public void run() {
try {
while (true) {
dout.writeUTF("What is your name? Written already write Exit.");
strrecieved = dis.readUTF();
if (strrecieved.equals("Exit")) {
System.out.println("Client " + this.s + " EXITED");
this.s.close();
this.dis.close();
this.dout.close();
break;
}
System.out.println("Client Messaged " + strrecieved);
}
} catch (Exception e) {
System.out.println(e);
}

}
}
Loading