Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何设置到无线到串行适配器的TCP客户端连接并使用java向其发送数据_Java_Networking_Tcp_Adapter - Fatal编程技术网

如何设置到无线到串行适配器的TCP客户端连接并使用java向其发送数据

如何设置到无线到串行适配器的TCP客户端连接并使用java向其发送数据,java,networking,tcp,adapter,Java,Networking,Tcp,Adapter,我是一名学习移动通信和电子工程的成熟学生,这使我能够学习Java,虽然我没有我想要的那么熟练,但这就是本文的目的 我的想法是,我想编写一个Java程序,连接到我的无线到串行适配器(Wiz6000)使用tcp连接,但问题是我有创建连接的代码,但当我将USB到串行转换器连接到适配器的串行输出并与超级终端建立链接时,wifi到串行适配器没有接收到数据 我已经在下面列出了我到目前为止的代码 import java.io.*; import java.net.*; public class Client

我是一名学习移动通信和电子工程的成熟学生,这使我能够学习Java,虽然我没有我想要的那么熟练,但这就是本文的目的

我的想法是,我想编写一个Java程序,连接到我的无线到串行适配器(Wiz6000)使用tcp连接,但问题是我有创建连接的代码,但当我将USB到串行转换器连接到适配器的串行输出并与超级终端建立链接时,wifi到串行适配器没有接收到数据

我已经在下面列出了我到目前为止的代码

import java.io.*;
import java.net.*;

public class Client1 {

    // Modify this value (xxx.xxx.x.xxx) to the IP address you want your client to connect to (the server’s IP address)
    static String hostString = "192.168.1.254"; 

    // Modify this value (xxxxx) to the port number that the server is accepting connections on
    static int portInt = 5000;  

    static Socket connectionSocket = null;
    static PrintWriter out = null;
    static BufferedReader in = null;
    static String fromUserString = null;
    static String fromServer = null;
    static BufferedReader stdIn = null;
    static String hostInetAddressString = null;  
    public int data;    

    public static void main(String[] args) {
        try {
            connectionSocket = new Socket(hostString, portInt);
            hostString = connectionSocket.getInetAddress().toString();
            out = new PrintWriter(connectionSocket.getOutputStream(), true);
            in = new BufferedReader(new   InputStreamReader(connectionSocket.getInputStream()));

            // Get the Inet Address of the connectionSocket and store it in the hostInetAddress InetAddress variable and then cast the hostInetAddress to a String named hostInetAddressString
            hostInetAddressString = connectionSocket.getInetAddress().toString();
            System.out.println("Connected to server with Inet Address " +     hostInetAddressString + " on port: " + connectionSocket.getPort() + "\n");
        }
        catch (Exception e) {
            System.err.println(e);
            System.exit(1);
        }

        // This is used to allow the client to receive input based on the program’s user pressing keys on their keyboard

        /* stdIn = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
        try {
        if (fromUserString != null) {
        int data=Integer.parseInt(fromUserString);
        out.println(fromUserString);
        fromUserString = null;
        }   
        }
        catch (Exception e) {
        System.err.println(e);
        break;
        }
        }*/
        try
        {
            // Create a new instance of a OutputStreamWriter object
            // attached to a ByteArrayOutputStream.
            ByteArrayOutputStream out = new ByteArrayOutputStream();

            OutputStreamWriter writer = new OutputStreamWriter(out, "ASCII");

            // Write to the output stream.
            String s = "Hello World";
            writer.write(s);
            writer.flush();

            // Display the contents of the ByteArrayOutputStream.
            System.out.println(out.toString());

            // Display the encoding being used.
            System.out.println("encoding: " + writer.getEncoding());

            // Close the OutputStreamWriter object.
            writer.close();
        }
        catch (IOException ex)
        {
            System.out.println(ex.toString());
        }
    }
我花了一周时间浏览了不同的网站,阅读了Java套接字客户端和服务器、串行通信和串行化,但我不知道该怎么做

其主要目的是创建一个连接到此wifi-to-serial适配器的应用程序,并从用户获取信息,然后通过wifi连接发送信息,在另一端,wifi-to-serial连接到控制数字显示的PCB。PCB是由我兼职工作的一家电子公司制造的,它的安装方式可以通过串行连接接收命令


因此,简而言之,我希望应用程序通过无线连接连接到数字显示器,并发送数据以显示。

看看您是否可以获得一个名为netcat(适用于大多数操作系统)的简单命令行程序,并使用它来测试系统中非java代码的所有部分。如果这样做行得通,那么您就知道问题出在代码中——但如果这样做行不通,那么您就知道除了代码中可能存在的任何问题之外,还有代码之外的问题。您还可以在侦听(服务器)模式下使用netcat对java代码进行测试。我刚刚下载了netcat,稍后将使用它。感谢您的评论。看看您是否可以获得一个名为netcat的简单命令行程序(适用于大多数操作系统),并使用它测试系统中所有非java代码的部分。如果这样做行得通,那么您就知道问题出在代码中——但如果这样做行不通,那么您就知道除了代码中可能存在的任何问题之外,还有代码之外的问题。您还可以在侦听(服务器)模式下使用netcat对java代码进行测试。我刚刚下载了netcat,稍后将使用它。谢谢你的评论。