使用 Java、TCP/IP 接收数据的速成课程帮助
我在接收简单的字符串数据类型时遇到问题,数据是通过端口 1180 从 IP 10.10.11.5 发送的(Labview 正在发送数据包)。当我尝试此代码时,出现连接错误。 错误消息:
java.io.IOException: ConnectException: connect refused
in virtual method #12 of com.sun.squawk.platform.posix.GCFSocketsImpl(bci=233)
at com.sun.squawk.io.j2me.socket.Protocol.open(bci=104)
in static method #4 of javax.microedition.io.Connector(bci=125)
at javax.microedition.io.Connector.open(231)
at javax.microedition.io.Connector.open(193)
at javax.microedition.io.Connector.open(177)
atedu.wpi.first.wpilibj.templates.RobotTemplate.robotInit(RobotTemplate.java:33)
at edu.wpi.first.wpilibj.IterativeRobot.startCompetition(IterativeRobot.java:74)
at edu.wpi.first.wpilibj.RobotBase.startApp(RobotBase.java:156)
in virtual method #10 of javax.microedition.midlet.MIDlet(bci=17)
at javax.microedition.midlet.MIDletTunnelImpl.callStartApp(64)
at com.sun.squawk.imp.MIDletMainWrapper.main(110)
in virtual method #95 of com.sun.squawk.Klass(bci=25)
at com.sun.squawk.Isolate.run(1506)
at java.lang.Thread.run(231)
in virtual method #47 of com.sun.squawk.VMThread(bci=42)
in static method #3 of com.sun.squawk.VM(bci=6)
提前感谢您的提示和帮助!
SocketConnection socketConnect;
InputStream myInputStream;
Datagram datagram;
DatagramConnection dataConnect;
String message;
DataInputStream stream;
public void robotInit() {
message = null;
try {
socketConnect = (SocketConnection) Connector.open("socket://10.10.11.5:1180");
myInputStream = socketConnect.openInputStream();
}
catch (IOException ex) {
ex.printStackTrace();
}
System.out.println(message);
}
编辑: 我们的设置很简单,但也很复杂。您看到的代码被放入 cRIO 中,它通过以太网电缆连接到我们的笔记本电脑。在 Labtop 上,我们使用 Labview 生成数据包,我们将这些数据包通过端口 1180 发送到 IP 10.10.11.2(cRIO 的 IP)。
I am having problems in receiving a simple String data type, the data is being sent from the IP 10.10.11.5 over port 1180 (Labview is sending the packet). When I try this code, I get an connection error.
Error Msg:
java.io.IOException: ConnectException: connect refused
in virtual method #12 of com.sun.squawk.platform.posix.GCFSocketsImpl(bci=233)
at com.sun.squawk.io.j2me.socket.Protocol.open(bci=104)
in static method #4 of javax.microedition.io.Connector(bci=125)
at javax.microedition.io.Connector.open(231)
at javax.microedition.io.Connector.open(193)
at javax.microedition.io.Connector.open(177)
atedu.wpi.first.wpilibj.templates.RobotTemplate.robotInit(RobotTemplate.java:33)
at edu.wpi.first.wpilibj.IterativeRobot.startCompetition(IterativeRobot.java:74)
at edu.wpi.first.wpilibj.RobotBase.startApp(RobotBase.java:156)
in virtual method #10 of javax.microedition.midlet.MIDlet(bci=17)
at javax.microedition.midlet.MIDletTunnelImpl.callStartApp(64)
at com.sun.squawk.imp.MIDletMainWrapper.main(110)
in virtual method #95 of com.sun.squawk.Klass(bci=25)
at com.sun.squawk.Isolate.run(1506)
at java.lang.Thread.run(231)
in virtual method #47 of com.sun.squawk.VMThread(bci=42)
in static method #3 of com.sun.squawk.VM(bci=6)
Thanks in advance for tips and help!
SocketConnection socketConnect;
InputStream myInputStream;
Datagram datagram;
DatagramConnection dataConnect;
String message;
DataInputStream stream;
public void robotInit() {
message = null;
try {
socketConnect = (SocketConnection) Connector.open("socket://10.10.11.5:1180");
myInputStream = socketConnect.openInputStream();
}
catch (IOException ex) {
ex.printStackTrace();
}
System.out.println(message);
}
EDIT:
Our setup is simple, yet complicated. The code you see is put onto a cRIO, it is connected to our laptop via Ethernet cable. On the Labtop we have Labview generating packets of data which we are sending over port 1180 to the IP of 10.10.11.2 (The IP of the cRIO).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为这是“编程错误” - 我几乎可以肯定问题是“网络配置”。
检查侦听器(服务器)程序和客户端之间是否有防火墙。
特别检查 Windows 防火墙。
如果您要访问公司路由器,您可能需要让站点的网络管理员参与进来,为您“打个洞”:)
I don't think it's a "programming error" - I'm almost certain the problem is "network configuration".
Check for any firewalls between your listener (server) program and the client.
Check for Windows firewall especially.
If you're going over a company router, you might have to get your site's network administrator involved to "punch a hole" for you :)