如何解决不同操作系统上的套接字问题。 XP和Windows 10 [英] How do I resolve sockets problems on different OS's. XP and windows 10

查看:171
本文介绍了如何解决不同操作系统上的套接字问题。 XP和Windows 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端例程,就像从XP计算机到另一台XP计算机的魅力一样。当我在Windows 10系统上使用相同的例程时,我得到一个未处理的异常,说连接尝试失败,因为连接方没有及时响应。



进口System.Net.Sockets

Imports System.Text

Class TCPCli

Shared Sub Main()



Dim tcpClient As New System.Net.Sockets.TcpClient()

tcpClient.Connect(127.0.0.1,8000)< ---这是违规行

Dim networkStream As NetworkStream = tcpClient.GetStream()

如果是networkStream.CanWrite和networkStream.CanRead那么

'做一个简单的写。

Dim sendBytes As [Byte]()= Encoding.ASCII.GetBytes(有人在那里)

networkStream.Write(sendBytes,0,sendBytes.Length)

'将NetworkStream读入字节缓冲区。

Dim bytes(tcpClient.ReceiveBufferSize)As Byte

networkStream.Read(bytes,0,CInt(tcpClient.ReceiveBufferSize))

'将从主机收到的数据输出到控制台。

Dim returndata As String = Encoding.ASCII.GetString(bytes)

Console.WriteLine((Host return:+ returndata))

Else

如果不是networkStream .CanRead然后

Console.WriteLine(不能不将数据写入此流)

tcpClient.Close()

其他

如果不是networkStream.CanWrite那么

Console.WriteLine(无法读取此流中的数据)

tcpClient.Close()

结束如果

结束如果

结束如果

'暂停,以便用户可以查看控制台输出

Console.ReadLine()

结束子



什么我试过了:



我已经厌倦了几种不同的网络配置设置。没有成功。较新的蓝牙系统不适用于较旧的蓝牙系统吗?这可以结束吗?我想要计算机的计算机有一个相当冗长的程序,可以连接我的铁路设置。

I have a Client routine that works like a charm from an XP computer to another XP computer. When I use the same routine on a Windows 10 system I get an unhandled exception saying " A connection attempt failed because the connected party didn't respond in time.

Imports System.Net.Sockets
Imports System.Text
Class TCPCli
Shared Sub Main()

Dim tcpClient As New System.Net.Sockets.TcpClient()
tcpClient.Connect("127.0.0.1", 8000) <---this is the offending line
Dim networkStream As NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
' Do a simple write.
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there")
networkStream.Write(sendBytes, 0, sendBytes.Length)
' Read the NetworkStream into a byte buffer.
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Output the data received from the host to the console.
Dim returndata As String = Encoding.ASCII.GetString(bytes)
Console.WriteLine(("Host returned: " + returndata))
Else
If Not networkStream.CanRead Then
Console.WriteLine("cannot not write data to this stream")
tcpClient.Close()
Else
If Not networkStream.CanWrite Then
Console.WriteLine("cannot read data from this stream")
tcpClient.Close()
End If
End If
End If
' pause so user can view the console output
Console.ReadLine()
End Sub

What I have tried:

I've tired several different network configuration set ups. With no success. Do newer bluetooth systems not work with older ones? Can this be over come. The computer I want to compunicate has a rather lengthy program that interfaces my railroad set up.

推荐答案

tcpClient.Connect("127.0.0.1", 8000) 

那将尝试连接到localhost而不是另一个系统。因此,当您的系统上没有运行服务器应用程序时,您将收到看到的错误消息。

That will try to connect to localhost and not to another system. So you will get the seen error message when the server application is not running on your system.


这篇关于如何解决不同操作系统上的套接字问题。 XP和Windows 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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