我正在尝试从RFID阅读器接收输出。制造商提供了允许用户通过TCP获取馈送的代码片段。 (https://support.impinj.com/hc/en-us/articles/202755278-Speedway-Connect#samplecode)
注意:阅读器与我正在使用的电脑在同一个wifi网络上
我的问题是:为什么主机允许使用Java进行连接并在使用C#时拒绝它?
我已经设法使用以下代码使用Java获得连接(我只需插入主机名和端口)
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class SpeedwayConnectClient
{
public static void main(String[] args)
{
// The IP address or hostname of your reader
final String READER_HOSTNAME = "SpeedwayR-10-27-52";
// The TCP port specified in Speedway Connect
final int READER_PORT = 14150;
try
{
// Create a TCP socket connection to the reader
Socket s = new Socket(READER_HOSTNAME, READER_PORT);
// Create a BufferedReader object from the socket connection
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
// Receive data in an infinite loop
while (true)
{
// Read one line at a time
String line = br.readLine();
// Print it to the screen
System.out.println(line);
}
}
catch (Exception e)
{
// An error has occurred
System.out.println(e.getMessage());
}
}
}
由于我无法使用Java(我已经设法在C#中)使用Firebase连接,因此我决定切换到C#。
我尝试使用来自同一网站的代码剪辑(C#one ofcourse):
结果是以下消息: “主持人拒绝了连接”
using System;
using System.Net.Sockets;
using System.IO;
namespace SpeedwayConnectClient
{
class Program
{
static void Main(string[] args)
{
// The IP address or hostname of your reader
const string READER_HOSTNAME = "SpeedwayR-10-27-52";
// The TCP port specified in Speedway Connect
const int READER_PORT = 14150;
try
{
// Create a new TCPClient
TcpClient client = new TcpClient();
// Connect to the reader
client.Connect(READER_HOSTNAME, READER_PORT);
// Get a reference to the NetworkStream
NetworkStream stream = client.GetStream();
// Create a new StreamReader from the NetworkStream
StreamReader streamReader = new StreamReader(stream);
// Receive data in an infinite loop
while (true)
{
// Read one line at a time
string line = streamReader.ReadLine();
// Print it to the screen
Console.WriteLine(line);
}
}
catch (Exception e)
{
// An error has occurred
Console.WriteLine(e.Message);
}
}
}
}