最近在学习socket编程,做了一个简单的客户端,我尝试用下面的代码连接google服务器但是一直没有反应,不知道错在哪里,请指教
- package com.test;
- import java.net.*;
- import java.util.*;
- import java.io.*;
- public class Test {
- public static void main(String[] args) throws Exception {
- Socket s=new Socket( "64.233.189.103",80 );
- InputStream is=s.getInputStream();
- OutputStream os=s.getOutputStream();
- Scanner sysIn=new Scanner( new BufferedInputStream(System.in));
- Scanner toClient=new Scanner( new BufferedInputStream(is));
- PrintWriter toServer=new PrintWriter(os,true);
- while(true){
- String request=sysIn.nextLine();
- toServer.println(request);
- while(toClient.hasNextLine()){
- System.out.println(toClient.nextLine());
- }
- }
- }
- }
|