Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27513

VS 2010 Winsock, hamachi, ''The requested address is not valid in its context''.... Help! =S

$
0
0
Hello all,

This is my first post on this forum, so first short introduction, I'm Daniël, a 17 year old programmer with an obsession for aviation... Today i started writing an application to fly so-called "shared cockpit" in Microsoft Flight Simulator. This application should include both the possibilities to serve as server or as client, connect to the other program over hamachi (so, on a specified IP address), then start sending data to synchronize both cockpits and planes. I decided to start with the connection part, as this is where I have the least experience with. Here is what I wrote so far (examples on the internet generally use much more code so maybe this looks stupid to you, but please remember this is the first time i work with winsock :sick:):

Code:

Option Explicit On

Imports FSUIPC
Imports System.Threading
Imports System.Net
Imports System.Net.Sockets
Imports System.Text

Public Class Form1

    Dim FSUIPCconnected As Boolean = False
    Private isConnectedFlag As Boolean
    Private Client As TcpClient
    Private Server As TcpListener
    Private mobjClient As TcpClient
    Private mode = 0 '0 is server, 1 is client

    Dim bytes(256) As Byte
    Dim data As String = Nothing

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        TextBox2.Text = "1544"
    End Sub

    Private Sub button1_click() Handles Button1.Click
        If isConnectedFlag = False Then
            Try
                Label4.Text = "Listening.."
                Server = New TcpListener(IPAddress.Any, Convert.ToInt32(TextBox2.Text))
                Server.Start()
                mobjClient = Server.AcceptTcpClient
                Label4.Text = "Connected"
                isConnectedFlag = True
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            If MsgBox("Are you sure you want to disconnect?", MsgBoxStyle.YesNo, "FS-Share") = MsgBoxResult.Yes Then
                Client.Close()
                Server.Stop()
            End If
        End If
    End Sub

    Private Sub button2_click() Handles Button2.Click
        If isConnectedFlag = False Then
            Try
                Dim EP As New IPEndPoint(IPAddress.Parse(TextBox1.Text), Convert.ToInt32(TextBox2.Text))
                Client = New TcpClient(EP)
                If Client.Connected = True Then
                    Label4.Text = "Connected"
                    isConnectedFlag = True
                Else
                    Label4.Text = "Not Connected"
                    isConnectedFlag = False
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            If MsgBox("Are you sure you want to disconnect?", MsgBoxStyle.YesNo, "FS-Share") = MsgBoxResult.Yes Then
                Client.Close()
                Server.Stop()
            End If
        End If
    End Sub

End Class

Compiling went good the first try immediately. Now using localhost (127.0.0.1) on the client all works fine, but when trying the hamachi IP (25.93.147.153) it throws an exception with the description: ''The requested address is not valid in its context'' (WSAEADDRNOTAVAIL). I already found out the exception was thrown when creating the winsock client, therefore it must be a winsock problem. Searching on google learned me that ''This normally results from an attempt to bind to an address that is not valid for the local machine.''. I have continued searching for the answer, tried some things myself, but nothing seems to work.... Anyone here who can help out please? I really don't know more what to do. :sick:

Thanks,
Daniël

Viewing all articles
Browse latest Browse all 27513

Trending Articles



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