0

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?

13
  • 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. Commented Jul 7, 2017 at 15:55
  • Internet. Is there no other way than forwarding? How e.g. games handle this? U do not forward every port in ur router there :) Commented Jul 7, 2017 at 15:58
  • IPAddress.Any says to listen on all connections, doesn't it? So it needs to listen on all IP's bc of various clients :) Commented Jul 7, 2017 at 16:00
  • 1
    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. Commented Jul 7, 2017 at 16:01
  • I'll give it a try :) Commented Jul 7, 2017 at 16:02

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Fantastic :) Thx for ur time. Didn't thought it's that easy... just port forwarding. I am really thankful for ur answer ;)
@realKSMC : Glad I could help! Just keep in mind that you must change your code back to what it was before if you some time are to connect with a client that keeps using the same connection. -- Good luck!
Do e.g. new games tunneling the port connections so that no port forwarding in the router is needed? The client also receives packets from the server.
@realKSMC : Receiving packets is not a problem once a connection has been established, but most games actually do not implement hole punching as it is not a common thing to do. It is easier to let the server hosts forward the port(s) in their router.
I'll add the opposite form as an answer. May u can help me there too. So the client is windows and linux is the server. Port 4001 is open, but also no connection. Have a look at below soon :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.