zoukankan      html  css  js  c++  java
  • android tcp发送接收数据笔记

    首先写发送数据的程序,再写接收数据的程序,否则对方无法接收到数据(原因未知)

    try {
                    tcpSocket = new Socket(Ip, Integer.parseInt(tcpPort));
                    while (true) {
                        //发送数据
                        Log.e("TCP开始发送:", "hello server!");
                        OutputStream OutStream = tcpSocket.getOutputStream();
                        OutStream.write("hello server!".getBytes());
                        OutStream.flush();
                        //接收数据
                        byte[] buffer = new byte[10000];
                        InputStream inputStream = tcpSocket.getInputStream();
                        DataInputStream input = new DataInputStream(inputStream);
                        int length = input.read(buffer);
                        String Msg = new String(buffer, 0, length, "gb2312");
                        Log.e("data:", Msg);
                        System.out.println("***Msg***"+Msg);
    
                    }
                } catch (Exception ex) {
                    Log.e("TCP发送接收:", ex.toString());
                    ex.printStackTrace();
                }
  • 相关阅读:
    [已解决] Python logging 重复打印日志信息
    scrapy
    Python 元编程
    MySQL性能优化 分区
    SQL Mode
    Golang 接口
    Python partial
    栈、队列(链表实现)
    Golang 位向量
    Java50题——学习以及思考
  • 原文地址:https://www.cnblogs.com/cekong/p/11433809.html
Copyright © 2011-2022 走看看