컴퓨터네트워크 - 자바 소켓프로그래밍을 이용한 야구게임
본 자료는 2페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
해당 자료는 2페이지 까지만 미리보기를 제공합니다.
2페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

컴퓨터네트워크 - 자바 소켓프로그래밍을 이용한 야구게임에 대한 보고서 자료입니다.

목차

1. 클라이언트 – 서버 흐름도

2. 클라이언트 입력 및 출력

3. 서버 진행과정

4. 후기

5. 소스코드
5.1 서버
5.2 클라이언트

본문내용

if(buf[2]==chcode[2]) S++;
if(buf[0]==chcode[1]) B++;
if(buf[0]==chcode[2]) B++;
if(buf[1]==chcode[2]) B++;
if(buf[1]==chcode[0]) B++;
if(buf[2]==chcode[0]) B++;
if(buf[2]==chcode[1]) B++;
if(S==0 && B==0)
resultSentence = "Out\n"; // 일치x
else if(S==3)
{
resultSentence = "Success\n"; //일치O
}
else //스트라이크, 볼 결과 생성
{
Sstring = Integer.toString(S);
Bstring = Integer.toString(B);
resultSentence = "S: " + Sstring + " " + "B: " + Bstring + "\n";
}
outToClient.writeBytes(resultSentence); //결과 클라이언트에 전송
S=0;B=0;
}
}
}
5.2 클라이언트
import java.io.*;
import java.net.*;
class TCPClient {
public static void main(String argv[]) throws Exception
{
String sentence; //입력 스트링
String serverSentence; //서버로부터 응답 스트링
int chance=10; //기회
char []an=new char[3]; //입력 문자열 변환
do{
Socket clientSocket = new Socket("localhost", 6789);
System.out.println("Chance: "+chance);
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
sentence = inFromUser.readLine();
for(int i=0;i<3;i++)
an[i]=sentence.charAt(i); //입력 스트링 변환( 중복 검사 위해 )
while(an[0]==an[1] || an[0]==an[2] || an[1]==an[2]) // 중복 검사
{
System.out.println("input error");
inFromUser = new BufferedReader(new InputStreamReader(System.in));
sentence = inFromUser.readLine();
for(int i=0;i<3;i++)
an[i]=sentence.charAt(i);
}
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
outToServer.writeBytes(sentence+'\n'); //서버로 스트링 전송
BufferedReader inFromServer = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
serverSentence = inFromServer.readLine(); //서버로부터의 스트링
System.out.println("FROM SERVER: " + serverSentence);
clientSocket.close();
chance--;
if(serverSentence.equals("Success"))
break;
} while(chance!=0);
if(chance==0)
System.out.println("false");
}
}
  • 가격1,500
  • 페이지수8페이지
  • 등록일2015.04.27
  • 저작시기2015.4
  • 파일형식한글(hwp)
  • 자료번호#965227
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니