Skip to content

Commit

Permalink
Single side chatting client
Browse files Browse the repository at this point in the history
  • Loading branch information
codewithRiC authored Jul 28, 2023
1 parent 0e92953 commit a6ea666
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// A Java program for a Client
import java.io.*;
import java.net.*;

public class Client {
// initialize socket and input output streams
private Socket socket = null;
private DataInputStream input = null;

private DataOutputStream out = null;

// constructor to put ip address and port
public Client(String address, int port)
{
// establish a connection
try {
socket = new Socket(address, port);
System.out.println("Connected");



// takes input from terminal
input = new DataInputStream(System.in);



// sends output to the socket
out = new DataOutputStream(
socket.getOutputStream());

// string to read message from input
String line = "";



// keep reading until "Over" is input
while (!line.equalsIgnoreCase("over")) {

line = input.readLine();
out.writeUTF(line);




}

// close the connection

input.close();

out.close();
socket.close();
}
catch (UnknownHostException u) {
System.out.println(u);
return;
}
catch (IOException i) {
System.out.println(i);
return;
}
}

public static void main(String args[])
{
Client client = new Client("127.0.0.1", 5000);
}
}

0 comments on commit a6ea666

Please sign in to comment.