套接字返回授权问题 [英] socket return commination issue

查看:75
本文介绍了套接字返回授权问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在制定控制/验证计划,以确保我们在电池组生产线上为每个工单使用正确的供应商单元。因为我们之前版本的程序在与机器软件的通信中无法正常工作。通信基于在本地计算机(IP 127.0.0.1,端口1003)上打开套接字,监听并写入其中。这样我们的程序和机器的软件就可以交换信息。



目前的状态是我的程序能够通过套接字收听来自机器软件的信息,但机器的软件无法接收我的程序在套接字中写入的内容。在这件事上我需要你的帮助。我试图写入套接字的方式是:





We are making a control/verification program to make sure we use the correct vendor’s cells for each work order on our battery pack line. Because our previous version of this program did not work properly in communication with the line machine’s software. The communication is based on opening a socket on the local machine (IP 127.0.0.1, port 1003), listening to it and writing in it. This way our program and the machine’s software can exchange information.

The current status is that my program is able to listen to the information coming from the machine’s software through the socket, but the machine’s software is not able to receive what my program is writing in the socket. I would need your help in this matter. The way I am trying to write into the socket is:


// Initialize TcpListener with the correct IP and port number and start listening
                this.listener = new TcpListener(serverIP, this.port);
                this.listener.Start(10);
                listener.Start();
                listener.BeginAcceptSocket(new AsyncCallback(DoAcceptSocketCallback), listener);
                clientConnected.WaitOne();
                     …
              // Initialize a NetworkStream using the opened socket
                this.listener = (TcpListener)ar.AsyncState;
                this.client = (TcpClient)ar.AsyncState;
                Socket clientSocket = this.listener.EndAcceptSocket(ar);
                NetworkStream tcpStream = new NetworkStream(clientSocket);
                NetworkStream tcpStream2 = this.client.GetStream();
 
              // Initialize a Streamreader for reading characters from the socket (Reading works OK)
                StreamReader barcodeStream = new StreamReader(tcpStream);
                char[] barcodeCharArray = new char[100];
                barcodeStream.Read(barcodeCharArray, 0, 100);
 
              // Initialize a Streamwriter for writing into the socket
                StreamWriter resultWriter1 = new StreamWriter(resultNetworkStream); // Does not work for writing in the socket
                StreamWriter resultWriter2 = new StreamWriter(tcpStream2);          // Does not work either
                resultWriter1.WriteLine(returnValue); // Does not work
                resultWriter2.WriteLine(returnValue); // Does not work

推荐答案

参见http://msdn.microsoft.com/en-us/library/fx6588te(v=vs.110).aspx [ ^ ]如何获取样本应该完成。
See http://msdn.microsoft.com/en-us/library/fx6588te(v=vs.110).aspx[^] for a sample of how it should be done.


这篇关于套接字返回授权问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆