소스올립니당...


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]

글쓴이 :[영돌이] 1998년 10월 10일 09:18:01

In Reply to: [Q] 소켓연결에서 ObjectInputStream과 ObjectOutputStream 쓰는법. posted by 박종엽 on 1998년 10월 10일 03:58:05:

- 서버 -
import java.io.*;
import java.net.*;
import java.util.Date;
import java.util.Vector;


public class DateServer extends Thread
{
protected ObjectOutputStream out;
protected Vector registry;

public DateServer(Socket s) throws IOException
{
registry = new Vector();

OutputStream o = s.getOutputStream();
BufferedOutputStream bO = new BufferedOutputStream(o);
out = new ObjectOutputStream(bO);
}

public void run()
{
try
{
registry.addElement(new Date());

out.writeObject(registry);
out.close();
}catch(IOException e){}
}

public static void main(String args[]) throws IOException
{
ServerSocket server = new ServerSocket(1905);

while(true)
{
System.out.println("waiting...");
Socket client = server.accept();
System.out.println("Accepted from "+client.getInetAddress());
DateServer c = new DateServer(client);
c.start();
}
}
}


- 클라이언트 -
import java.io.*;
import java.net.*;
import java.util.Date;
import java.util.Vector;


public class DateClient
{
public static void main(String args[]) throws IOException, ClassNotFoundException
{
Socket s = new Socket("127.0.0.1",1905);
ObjectInputStream in = new ObjectInputStream(s.getInputStream());
Vector when = (Vector)in.readObject();
in.close();
System.out.println((Date)when.elementAt(0));
}
}


소스 설명은 너무도 간단해서....
그냥 날짜,시간 찍는것임당...



다음 글들:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
HTML 태그 포함 여부: HTML 문서일 경우 체크
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]