Skip to content
Snippets Groups Projects
Commit 2ccd6b17 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

Homework 1 submission with refactor/rename to have student name first

parent 3f6a88f2
No related branches found
No related tags found
No related merge requests found
File added
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mv3500_assignments;
import java.io.*;
import java.net.*;
/**
*
* @author Rico
*/
public class LandasClient1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try
{
System.out.println("Creating Socket");
Socket cs = new Socket("localhost", 2317);
while (true) {
PrintStream cp = new PrintStream(cs.getOutputStream());
System.out.print("\nClient: \n");
System.out.print("Please enter entity identifier and position: ");
InputStreamReader cir = new InputStreamReader(System.in);
BufferedReader cbr = new BufferedReader(cir);
String temp1 = cbr.readLine();
cp.println(temp1);
BufferedReader cbr1 = new BufferedReader(new InputStreamReader(cs.getInputStream()));
String temp2 = cbr1.readLine();
System.out.print(temp2);
}
}
catch(Exception e)
{
System.out.println(e);
System.out.println(" Problem with client");
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mv3500_assignments;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;
/**
*
* @author Rico
*/
public class LandasClient2 {
public static DataInputStream in;
public static DataOutputStream out;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//declare a scanner so we can write a message
Scanner keyboard = new Scanner(System.in);
// localhost ip
String ip = "127.0.0.1";
int port = 2317;
Socket socket;
try {
//connect
socket = new Socket(ip, port);
//initialize streams
//DataInputStream in = new DataInputStream(socket.getInputStream());
//DataOutputStream out = new DataOutputStream(socket.getOutputStream());
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());
while (true){
System.out.print("\nMessage to server: ");
//Write a message
String message = keyboard.nextLine();
//Send it to the server which will print it and send a confirmation
out.writeUTF(message);
// recieve the incoming messages and print
String message2 = in.readUTF();
System.out.println(message2);
}
}
catch(IOException e) {
System.out.println(e);
System.out.println("\nProblem with client");
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mv3500_assignments;
import java.io.*;
import java.net.*;
/**
*
* @author Rico
*/
public class LandasServer1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try
{
ServerSocket ss = new ServerSocket(2317);
while(true) {
Socket cs = ss.accept();
BufferedReader cbr = new BufferedReader(new InputStreamReader(cs.getInputStream()));
String temp = cbr.readLine();
//System.out.println("Client:" + temp);
//JOptionPane.showMessageDialog(null,"Salam");
PrintStream spr = new PrintStream(cs.getOutputStream());
String temp1 = "Server: I got your message: " + temp;
spr.println(temp1);
//server();
}
}
catch(Exception e) {
System.out.println("problem with networking");
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mv3500_assignments;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
/**
*
* @author Rico
*/
public class LandasServer2 {
public static DataInputStream in;
public static DataOutputStream out;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int port = 2317;
ServerSocket server;
Socket clientSocket;
try {
//start listening on port
server = new ServerSocket(port);
System.out.println("Listening on port: " + port);
//Accept client
clientSocket = server.accept();
System.out.println("Client Connected!");
//initialize streams so we can send message
in = new DataInputStream(clientSocket.getInputStream());
out = new DataOutputStream(clientSocket.getOutputStream());
String message;
while (true) {
// as soon as a message is being received, print it out!
message = in.readUTF();
System.out.println("Server received: " + message);
// send a message confirmation to the client
String temp1 = "Server: I received your message of " + "'" + message + "'";
out.writeUTF(temp1);
}
}
catch(IOException e) {
System.out.println("problem with networking: " + e);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment