0

Actually I create an connection between windows-clients and a linux server using vb.net for the client and netcat for the server. The problem is that I cannot receive anything using client_receive(), because I cannot send back data from the server to the client inside the open netcat socket connection. Also I am looking for a way to not directly respond to an client - rather time-independent. The connection needs to keep open and the server can say anything to an connected client using e.g. echo '$message' > /dev/tcp/client.ip/4000 in combination with screen. The important thing is that it needs to be the same connection, no new.

With the following code I am able to send strings to an port netcat is listening to:

 Dim stream As NetworkStream
    Dim streamw As StreamWriter
    Dim streamr As StreamReader
    Dim myclient As New TcpClient
    Dim IP As String = "example.com"
    Dim Port As Integer = 4000

Public Sub client_send(ByVal text As String)
        streamw.WriteLine(text)
        streamw.Flush()
    End Sub
    Public Function client_receive() As String
        client_receive = streamr.ReadLine
    End Function



Private Sub Welcome_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Try
            myclient.Connect(IP, Port)
            stream = myclient.GetStream
            streamw = New StreamWriter(stream)
            streamr = New StreamReader(stream)

        Catch
        End Try

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles iamonline.Tick
        client_send("ItzMe")
        MessageBox.Show(client_receive)
    End Sub

We send ItzMe every 5 seconds to the port 4000/tcp. In the netcat screen we see:

ItzMe
ItzMe
...

Update #1: Changed Timer1

Update #2: Detailed the question

1 Answer 1

2

Try this:

while true ; do nc -l -p 4000 -c 'echo -e "message received"'; done

Using socat, you can create a simple echo server:

socat -v tcp-l:4000,fork exec:'/bin/cat'

Alternatively if you do not have the -c parameter:

mkfifo fifo
cat fifo  | nc -k -l 4000 -v | cat  > fifo
Sign up to request clarification or add additional context in comments.

6 Comments

while true; do echo -e "ur welcome!\n" | nc -k -l -p 4000 done. Sorry I forgot to add the keepalive earlier.
Tried while true; do echo -e "ur welcome!\n" | nc -k -l -p 4000; done. Textbox appears two times, but the second one is empty and finally GUI freezes and netcat session get a total of 3 times ItzMe.
Also I am looking for a way to not directly respond to an client - rather time-independent. The connection needs to keep open and the server can say anything to the client using e.g. screen. Hope you understand :)
- updated the question to explain more what the goal is.
I have incorporated a echo server solution using socat or nc.
|

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.