Information is being sent to our server on port 4124 and I am trying to build an application that will get the information and put into a file (or even print on the screen).
thanks in advance
***************************
import java.io.*;
import java.net.*;
import java.util.*;
public class DateServer extends Thread {
private ServerSocket dateServer;
public static void main(String argv[]) throws Exception {
new DateServer();
}
public DateServer() throws Exception {
dateServer = new ServerSocket(4124);
System.out.println("Server listening on port 4124."
this.start();
}
public void run() {
while(true) {
try {
System.out.println("Waiting for connections."
Socket client = dateServer.accept();
System.out.println("Accepted a connection from: "+
client.getInetAddress());
Connect c = new Connect(client);
} catch(Exception e) {}
}
}
}
class Connect extends Thread {
private Socket client = null;
private InputStream ois = null;
private OutputStream oos = null;
public Connect() {}
public Connect(Socket clientSocket) {
client = clientSocket;
try {
ois = new ObjectInputStream(client.getInputStream());
} catch(Exception e1) {
try {
client.close();
}catch(Exception e) {
System.out.println(e.getMessage());
}
return;
}
this.start();
}
public void run() {
try {
String timestamp=null;
BufferedReader in=new BufferedReader(new InputStreamReader(ois));
System.out.println("Connected to :"+client.getInetAddress()+" on port "+client.getPort());
while(true){
System.out.println("test"
timestamp=in.readLine();
System.out.println(timestamp);
System.out.println("test1"
if(timestamp==null)
{
System.out.println("Sever closed connection"
break;
}
System.out.println(timestamp);
}
}
catch(IOException e){System.out.println(e);}
finally
{
//oos.writeObject(new Date());
//oos.flush();
// close streams and connections
//ois.close();
//oos.close();
//client.close();
}
}
}
thanks in advance
***************************
import java.io.*;
import java.net.*;
import java.util.*;
public class DateServer extends Thread {
private ServerSocket dateServer;
public static void main(String argv[]) throws Exception {
new DateServer();
}
public DateServer() throws Exception {
dateServer = new ServerSocket(4124);
System.out.println("Server listening on port 4124."
this.start();
}
public void run() {
while(true) {
try {
System.out.println("Waiting for connections."
Socket client = dateServer.accept();
System.out.println("Accepted a connection from: "+
client.getInetAddress());
Connect c = new Connect(client);
} catch(Exception e) {}
}
}
}
class Connect extends Thread {
private Socket client = null;
private InputStream ois = null;
private OutputStream oos = null;
public Connect() {}
public Connect(Socket clientSocket) {
client = clientSocket;
try {
ois = new ObjectInputStream(client.getInputStream());
} catch(Exception e1) {
try {
client.close();
}catch(Exception e) {
System.out.println(e.getMessage());
}
return;
}
this.start();
}
public void run() {
try {
String timestamp=null;
BufferedReader in=new BufferedReader(new InputStreamReader(ois));
System.out.println("Connected to :"+client.getInetAddress()+" on port "+client.getPort());
while(true){
System.out.println("test"
timestamp=in.readLine();
System.out.println(timestamp);
System.out.println("test1"
if(timestamp==null)
{
System.out.println("Sever closed connection"
break;
}
System.out.println(timestamp);
}
}
catch(IOException e){System.out.println(e);}
finally
{
//oos.writeObject(new Date());
//oos.flush();
// close streams and connections
//ois.close();
//oos.close();
//client.close();
}
}
}