0
votes

The goal is an vb.net connection between windows and linux.

windows-server (vb.net): The server should listen on port 4001/tcp for connections and do something with the packets.

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-client: The client should create an connection with the server and send him packets.

echo "iamhere" > /dev/tcp/client.ip/4001

The problem is that it seems like the server does not open port 4001/tcp. The client gets no connection :/

How to fix that?

1
Are you connecting over LAN or over the internet? If the latter you must port forward port 4001 in your router. Also I don't see you specify what IP to connect to on linux.Visual Vincent
Internet. Is there no other way than forwarding? How e.g. games handle this? U do not forward every port in ur router there :)realKSMC
IPAddress.Any says to listen on all connections, doesn't it? So it needs to listen on all IP's bc of various clients :)realKSMC
The server must almost always port forward unless it uses hole punching (advanced!). The client usually mustn't as outgoing connections are usually automatically opened in the NAT filter.Visual Vincent
I'll give it a try :)realKSMC

1 Answers

1
votes

The reason the connection doesn't work is because you've got to forward port 4001 in the server's router. Currently it is dropped by the router because the port is not mapped in the router's NAT table, so the router does not know to which LAN device it should send the packet.

As for the message box only being shown once, if that Linux code of yours creates a new TCP connection then you gotta change your code to discard old connections after receiving a message:

 Try
    Server = New TcpListener(ipendpoint)
    Server.Start()
    While True 'Moved While up here to wait for new connections after every command.
        serverclient = Server.AcceptTcpClient
        serverstream = serverclient.GetStream
        serverstreamr = New StreamReader(serverstream)
        serverstreamw = New StreamWriter(serverstream)
        Select Case serverstreamr.ReadLine
            Case "onl" '........
            Case "logoff" '........
            Case "iamhere" '........
                MessageBox.Show("WORKS!!!")
        End Select
        serverclient.Close() 'Close old connection.
    End While
Catch
End Try

The reason we do this is because if Linux starts a new connection and the server doesn't, then the server will still be waiting for data on the old connection which isn't used anymore by Linux.