Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

TCP/IP Server on Netduino+ - Problems


  • Please log in to reply
6 replies to this topic

#1 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 03 August 2012 - 09:45 PM

Hi,

I'm trying to make my tcp/ip server for my net+ board. But it dont works.
I have 2Years with vb, but only 3Days with netduino and thats my Problem. Please can someone help me?

Here is my code (for the Netduino):
Imports System.Net.Sockets
Imports System.IO
Imports System.Net


Module Module1
    Private server As TcpListener
    Private client As New TcpClient
    Private ipendpoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 8000) ' eingestellt ist port 8000. dieser muss ggf. freigegeben sein!
    Private list As New List(Of Connection)

    Private Structure Connection
        Dim stream As NetworkStream
        Dim streamw As StreamWriter
        Dim streamr As StreamReader
        Dim nick As String ' natürlich optional, aber für die identifikation des clients empfehlenswert.
    End Structure

    Private Sub SendToAllClients(ByVal s As String)
        For Each c As Connection In list ' an alle clients weitersenden.
            Try
                c.streamw.WriteLine(s)
                c.streamw.Flush()
            Catch
            End Try
        Next
    End Sub

    Sub Main()
        Console.WriteLine("Der Server läuft!")
        server = New TcpListener(ipendpoint)
        server.Start()

        While True ' wir warten auf eine neue verbindung...
            client = server.AcceptTcpClient

            Dim c As New Connection ' und erstellen für die neue verbindung eine neue connection...
            c.stream = client.GetStream
            c.streamr = New StreamReader(c.stream)
            c.streamw = New StreamWriter(c.stream)

            c.nick = c.streamr.ReadLine ' falls das mit dem nick nicht gewünscht, auch diese zeile entfernen.

            list.Add(c) ' und fügen sie der liste der clients hinzu.
            Debug.Print(c.nick & " has joined.")
            ' falls alle anderen das auch lesen sollen können, an alle clients weiterleiten. siehe SendToAllClients

            Dim t As New Threading.Thread(AddressOf ListenToConnection)
            t.Start(c)
        End While
    End Sub

    Private Sub ListenToConnection(ByVal con As Connection)
        Do
            Try
                Dim tmp As String = con.streamr.ReadLine ' warten, bis etwas empfangen wird...
                Debug.Print(con.nick & ": " & tmp)
                SendToAllClients(con.nick & ": " & tmp) ' an alle clients weitersenden.

            Catch ' die aktuelle überwachte verbindung hat sich wohl verabschiedet.
                list.Remove(con)
                Debug.Print(con.nick & " has exit.")
                Exit Do
            End Try
        Loop
    End Sub
End Module

Or is there an Network Tutorial in VisualBasic? =)

Sorry for my bad english.

mfg & thx

gfcwfzkm

#2 Valkyrie-MT

Valkyrie-MT

    Advanced Member

  • Members
  • PipPipPip
  • 315 posts
  • LocationIndiana, USA

Posted 04 August 2012 - 12:05 AM

What error are you seeing and on what line number? What firmware version are you running? -Valkyrie-MT

#3 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 04 August 2012 - 08:02 AM

I use firmware 4.2 RC3.

It can't import System.Net.Sockets and System.net
Now i have on every word with tcp... or stream... an error.

And i can't start a new thread:
Dim t As New Threading.Thread(AddressOf [u]ListenToConnection[/u])
            t.Start([u]c[/u])


#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 04 August 2012 - 10:33 AM

Hi gfcwfzkm',

It can't import System.Net.Sockets and System.net
Now i have on every word with tcp... or stream... an error.

Can you please make sure that the following assemblies are included in your project?
System.dll, Microsoft.SPOT.Net.dll

They should be included by default...but if they aren't then you'll want to add them in.

And i can't start a new thread:

Dim t As New Threading.Thread(AddressOf [u]ListenToConnection[/u])
            t.Start([u]c[/u])

When you try to start a new thread, what error do you get?

Also...I would recommend upgrading to the latest release candidate firmware. We can't provide much support on older betas.

Chris

#5 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 04 August 2012 - 09:02 PM

Uff, Done. NetduinoPlus is full updated to 4.2 RC5 =) And... Visual Basic 2010 and Visual Studio shows the same errors. I tried to add the "Toolbox.NETMF.NET" from the Samples and it dont works too. i need it to connect a PC-Programm over a LAN cable to the netduino and to send some commands like "OUT1=ON". is there better methods to make that? EDIT:\\ Is Telnet maybe a better way than TCP/IP? mfg & thx gfcwfzkm

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 15 August 2012 - 11:10 AM

Hi gfcwfzkm, Quick note: the official .NET MF 4.2 firmware has now been posted. Let's update your boards to the official release and then, if a problem still exists, see what we can do to get you up and running... Chris

#7 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 23 August 2012 - 08:20 PM

it dont works. is there not an System.Net lib for netduino+? Or some other methods to make a tcp-server on netduino+? mfg & thx gfc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.