Skip to content

Instantly share code, notes, and snippets.

Created March 25, 2014 21:06
Show Gist options
  • Save anonymous/9771388 to your computer and use it in GitHub Desktop.
Save anonymous/9771388 to your computer and use it in GitHub Desktop.
package tcp;
import java.io.*;
import java.net.*;
/**
*
* @author Rashid
*/
public class Server {
public static void main(String[] args ) throws Exception{
String clientSentence;
String capitalizedSentence;
// Creating Server Port 6789
ServerSocket welcomeSocket = new ServerSocket(6789);
System.out.println("Server Started and listening to the port 6789");
while(true) {
// The server accepts the waiting client
Socket connectionSocket = welcomeSocket.accept();
// IN
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); // OUT
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
// READ LINE
clientSentence = inFromClient.readLine();
// UPPER CASE
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
}
}
package tcp;
import java.io.*;
import java.net.*;
public class TCP {
public static void main(String[] args) throws Exception {
String Sentence;
String modifiedSentence;
// File Reading
//-----------------
// -----------------
// Open Connection to the Port 6789
// First Parameter is Server-Address and Second: is the Port
Socket clientSocket = new Socket("localhost",6789);
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
PrintWriter toServer = null;
toServer = new PrintWriter(clientSocket.getOutputStream(), true);
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment