目標是windows和linux之間的vb.net連接。在Linux上使用VB.net進行Windows TCP套接字連接
windows-server(vb.net):服務器應該在端口4001/tcp上監聽連接,並對數據包執行一些操作。
Dim serverstream As NetworkStream
Dim serverstreamw As StreamWriter
Dim serverstreamr As StreamReader
Dim Server As TcpListener
Dim serverclient As New TcpClient
Dim ipendpoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 4001)
Dim mainthread As Threading.Thread
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
mainthread = New Threading.Thread(AddressOf mainserver)
mainthread.Start()
End Sub
Sub mainserver()
Try
Server = New TcpListener(ipendpoint)
Server.Start()
serverclient = Server.AcceptTcpClient
serverstream = serverclient.GetStream
serverstreamr = New StreamReader(serverstream)
serverstreamw = New StreamWriter(serverstream)
While True
Select Case serverstreamr.ReadLine
Case "onl" '........
Case "logoff" '........
Case "iamhere" '........
MessageBox.Show("WORKS!!!")
End Select
End While
Catch
End Try
End Sub
Linux的客戶端:客戶端應該創建與服務器的連接併發送數據包他。
echo "iamhere" > /dev/tcp/client.ip/4001
的問題是,它似乎像服務器不開端口4001/TCP。客戶端沒有連接:/
如何解決這個問題?
您是通過局域網還是通過互聯網連接?如果是後者,則必須在路由器中轉發端口4001。此外,我沒有看到你指定什麼IP連接_ **到** _在Linux上。 –
互聯網。除了轉發之外,沒有別的辦法嗎?如何遊戲處理這個? U不要轉發你的路由器中的每個端口:) – realKSMC
'IPAddress.Any'表示監聽所有連接,不是嗎?所以它需要監聽所有IP的各種客戶端的bc :) – realKSMC