Main
package main;
public class mainClass {
public static void main(String[] args) throws Exception{
ServerSocket serSocket = new ServerSocket(9000);
System.out.println("대기중...");
Socket socket = serSocket.accept();
System.out.println("client IP : " + socket.getInetAddress()
+ " Port : " + socket.getPort());
//recv
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
MemberDto dto = (MemberDto) ois.readObject();
//출력
System.out.println("client로 부터 DTO : " + dto.toString());
//send
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(dto);
oos.flush();
}
}
Dto
package dto;
import java.io.Serializable;
//Serialize (직렬화)전송 -> 순서를 정해야함 -> 설정해줌
public class MemberDto implements Serializable{
/**
*
*/
private static final long serialVersionUID = 7159726773562029167L;
private int number;
private String name;
public MemberDto() {
// TODO Auto-generated constructor stub
}
public MemberDto(int number, String name) {
super();
this.number = number;
this.name = name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "MemberDto [number=" + number + ", name=" + name + "]";
}
}
'JAVA > 기초 프로그래밍' 카테고리의 다른 글
쓰레드 기본개념 (0) | 2020.06.15 |
---|---|
쓰레드//어레이리스트//채팅 (0) | 2020.06.15 |
쓰레드 예) (0) | 2020.06.15 |
TCP// 쓰레드 문자열 전송 기본 (0) | 2020.06.15 |
팩토리// 무기, 폭탄 사용게임 (0) | 2020.06.11 |