package protocol;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.InetAddress;
import java.net.Socket;
public class SocketClient {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
InetAddress address = null;
Socket socket = null;
// BufferedReader in = null;
// PrintWriter out = null;
DataInputStream dis = null;
DataOutputStream dos = null;
try {
address = InetAddress.getLocalHost();
socket = new Socket(address, 20248);
//socket = new Socket(address, 9000);
//in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
dis = new DataInputStream(socket.getInputStream());
dos = new DataOutputStream(socket.getOutputStream());
for(;;){
dos.write("123456789".getBytes(), 0, "123456789".getBytes().length-1);
// String consoleIn = console.readLine();
// out.write(consoleIn);
// out.flush();
// if (consoleIn != null && consoleIn.equals("end")) {
// break ;
// }
//String read = in.readLine();
//System.out.println("From server=" + read);
}//end for
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
try{
dis.close();
dos.close();
socket.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
java socket通信自定义消息协议
共4个文件
java:4个
4星 · 超过85%的资源 需积分: 50 506 下载量 36 浏览量
2010-05-26
16:26:34
上传
评论 6
收藏 2KB RAR 举报
温馨提示
java socket通信自定义消息协议,socket以字节码的方式通信传递,客户端与服务器端分别进行转换与解析的过程实现简单的消息协议。
资源推荐
资源详情
资源评论
收起资源包目录
Protocol.rar (4个子文件)
SocketClient.java 2KB
SocketServer.java 798B
Message.java 618B
ServerThread.java 1KB
共 4 条
- 1
gaohf
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页