Archive for February, 2010
Open up the two java programs given below (SimpleServer & SimpleClient) using your JAVA IDE (I prefer JCreator) separately. Buid it and run the SimpleServer 1st then run SimpleClient. Now start chating.
SimpleServer Source Code:
import java.net.*;
import java.io.*;
import java.util.*;
import java.text.DateFormat;
public class SimpleServer {
public static void main(String args[]) {
ServerSocket s = null;//Input From Keyboard
String str;
DataInputStream indata= new DataInputStream (System.in);
System.out.println(”Type in Something & Press Enter to Send it To The >>C L I E N T<<: “);
// Register your service on port 5432
try {
s = new ServerSocket(5432);
} catch (IOException e) {
// ignore
}
// Run the listen/accept loop forever
while (true) {
try {
// Wait here and listen for a connection
Socket s1 = s.accept();
// Get output stream associated with the socket
OutputStream s1out = s1.getOutputStream();
DataOutputStream dos = new DataOutputStream(s1out);System.out.println();
System.out.println(”Write Something: “);
str=indata.readLine();
dos.writeUTF(str);// Get an input stream from the socket
InputStream is = s1.getInputStream();// Decorate it with a “data” input stream
DataInputStream dis = new DataInputStream(is);
// Read the input and print it to the screen
System.out.println(”Incoming From Client>>>:” +dis.readUTF());
//Display System Date
DateFormat defaultDate = DateFormat.getDateInstance();
System.out.println(defaultDate.format(new Date()));
//Display System Time
DateFormat shortTime = DateFormat.getTimeInstance(DateFormat.SHORT);
System.out.println(shortTime.format(new Date()));// Close the connection, but not the server socket
dos.close();
s1.close();
dis.close();
} catch (IOException e) {
// ignore
}
}
}
}
SimpleClient Source Code
import java.net.*;
import java.io.*;
import java.util.*;
import java.text.DateFormat;
public class SimpleClient {
public static void main(String args[]) {//Input From Keyboard
String str;
DataInputStream indata= new DataInputStream (System.in);System.out.println(”Type in Something & Press Enter to Send it To The >>S E R V E R<<: “);
while(true){
try {
// Open your connection to a server, at port 5432
// localhost used here
Socket s1 = new Socket(”127.0.0.1″, 5432);
// Get an input stream from the socket
InputStream is = s1.getInputStream();
// Decorate it with a “data” input stream
DataInputStream dis = new DataInputStream(is);
// Read the input and print it to the screen
System.out.println(”Incoming From Server>>>:” +dis.readUTF());
//Display System Date
DateFormat defaultDate = DateFormat.getDateInstance();
System.out.println(defaultDate.format(new Date()));
//Display System Time
DateFormat shortTime = DateFormat.getTimeInstance(DateFormat.SHORT);
System.out.println(shortTime.format(new Date()));// Get output stream associated with the socket
OutputStream s1out = s1.getOutputStream();
DataOutputStream dos = new DataOutputStream(s1out);
System.out.println();
System.out.println(”Write Something: “);
str = indata.readLine();
dos.writeUTF(str);// When done, just close the steam and connection
dis.close();
dos.close();
s1.close();
} catch (ConnectException connExc) {
System.err.println(”Could not connect to the server.”);
} catch (IOException e) {
// ignore
}
}
}
}
Enjoy. Don’t forget to give me feedback. If you face any difficulties please let me know.

It is possible to run graphics program using Turbo C in vista. All you have to do is to run your OS in SAFE MODE & use <graphics.h> header file. And you must have ‘BGI’ directory present in your TC folder. (C:\\TC\BGI)
Go to BGI directory (folder) & copy BGIDEMO.C. Now go to TC\BIN and paste it. After That Open up your compiler which is in BIN folder (tc.exe).
If your compiler opens up in small window don’t panic. Press ALTER+ENTER to maximize it.
Now open BGIDEMO.C using your compiler. (File>Open or press F3). Now Run it. If the program give no response use these codes after the main function:
int gd=DETECT, gm;
initgraph(&gd,&gm,”c:\\TC\\bgi”);
Now save it and Run.
Happy coding.




