android网络编程 socket,求助,实在搞不明白了,安卓Socket编程

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

package com.example.mwifi;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.PrintWriter;

import java.net.InetSocketAddress;

import java.net.Socket;

import java.net.UnknownHostException;

import com.example.socket.SocketUtil;

import android.app.Activity;

import android.os.Bundle;

import android.text.method.ScrollingMovementMethod;

import android.view.View;

import android.widget.EditText;

import android.widget.TextView;

public class Client extends Activity {

EditText et_message;

TextView tv_show;

PrintWriter pw=null;

BufferedReader br=null;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_client);

ShiLiHuaKongJian();

new Thread(new TestClient()).start();

}

public void ShiLiHuaKongJian(){

et_message=(EditText)findViewById(R.id.et_message);

et_message.setMovementMethod(ScrollingMovementMethod.getInstance());

tv_show=(TextView)findViewById(R.id.textView1);

}

Socket socket=null;

class TestClient implements Runnable{

@Override

public void run() {

// TODO Auto-generated method stub

try {

System.out.println("hhhhhhhhh");

if(socket==null||socket.isClosed()){

System.out.println("kkkkk");

socket =new Socket();

socket.connect(new InetSocketAddress("192.168.1.102", 8001), 3000);

System.out.println("nhoaadddd");

System.out.println(socket.getRemoteSocketAddress().toString()+"dddddd");

getIO();

}else{

System.out.println("socket连接上了");

}

} catch (UnknownHostException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

public void getIO() throws IOException{

pw=SocketUtil.doWriter(socket);

br=SocketUtil.getRead(socket);

}

public void doClick(View view){

String message=et_message.getText().toString();

if(pw==null){

System.out.println("pw is null");

}

pw.println(message);

pw.flush();

}

}

大神们看看哪里错了,socket连接不上,ip地址是正确的,不知道为啥错了,报空指针

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值