Quantcast
Viewing all articles
Browse latest Browse all 27201

Client server both ways communication

For the past 3 days I've been working on the communication block of my application, though I've been struggling because of the port forwarding, which did not properly work, even using NATUPNPLib. Searching on the Internet about solutions for my problem I found out that applications like Skype, Messenger and Steam don't need port forwarding because they are the ones that connect to a server(don't listen to a port). So I decided to do something like this.

TCP Testing App code:

Code:

Imports System.Net
Imports System.IO

Public Class Form1

    Dim LocalHostaddress As String = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList(1).ToString()
    Dim listener As Net.Sockets.TcpListener
    Dim listenthread As Threading.Thread
    Dim Reader As StreamReader
    Dim Writer As StreamWriter
    Dim IP As String = "1.1.1.1"
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        listener = New Net.Sockets.TcpListener(Net.IPAddress.Any, 10)
        listener.Start()
        listenthread = New Threading.Thread(AddressOf receive)
        listenthread.IsBackground = True
        listenthread.Start()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        send()
    End Sub

    Private Sub receive()
        Do
            Dim ClientReader As New Sockets.TcpClient
            ClientReader.Connect(IP, 10)
            Reader = New StreamReader(ClientReader.GetStream)
            MsgBox(Reader.ReadToEnd)
        Loop
    End Sub

    Private Sub send()
        Dim ClientWrite As New Sockets.TcpClient
        ClientWrite.Connect(IP, 11)
        Writer = New StreamWriter(ClientWrite.GetStream)
        Writer.Write("something")
        Writer.Close()
    End Sub
End Class

Am I on the right track?
If I make a proper application on the other end is this going to work?

Viewing all articles
Browse latest Browse all 27201

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>