Simple send by Socket - Netduino 3 - Netduino Forums
   
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

Simple send by Socket

TCP Socket.Send

  • Please log in to reply
4 replies to this topic

#1 claudio.serio

claudio.serio

    Member

  • Members
  • PipPip
  • 25 posts

Posted 11 January 2016 - 04:18 PM

I wrote this simple code to send a string to a client, once it attached to my listen:

 

Module Module1
    Dim Listen_Thread As Thread
    Dim Client_Thread As Thread
    Private Listener As System.Net.Sockets.Socket
    Private ClientSocket As System.Net.Sockets.Socket
    Private bmsg() As Byte
    Sub Main()
        ' write your code here
        Dim Msg As String = "This is a transmission test to check the first message. I hope it arrives safety and quickly .... bye bye !"
        Dim sMsg() As Char = Msg.ToCharArray
        ReDim bmsg(sMsg.Length - 1)
        Dim i As Integer
        For i = 1 To sMsg.Length
            bMsg(i - 1) = CByte(Microsoft.VisualBasic.Strings.AscW(sMsg(i - 1)))
        Next
        Listener = New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp)
        Dim ListEndPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Any, 5001)
        Listener.Bind(ListEndPoint)
        Listener.Listen(1)
 
        Listen_Thread = New Thread(AddressOf listener_thread)
        Listen_Thread.Start()
 
    End Sub
    Private Sub listener_thread()
        While (True)
            Try
                ClientSocket = Listener.Accept
                Debug.Print("Client accepted ")
                Client_Thread = New Thread(AddressOf Clienter_thread)
                Client_Thread.Start()
 
            Catch ex As System.Net.Sockets.SocketException
                Debug.Print("Error, not connected  .. : " & ex.Message)
                If Not Client_Thread Is Nothing Then
                    Client_Thread.Abort()
                    Client_Thread = Nothing
 
                End If
            End Try
        End While
    End Sub
 
    Private Sub Clienter_thread()
 
        While (True)
            Dim MessReady As Boolean = False
            Thread.Sleep(1000)
            Debug.Print("bytes send")
            ClientSocket.Send(bmsg)
        End While
 
    End Sub
 
End Module
 
Then i run and opened HyperTerminal
 
It works for a while ... then in Hyperterminal i receive a lot of characters and it stop.
You can check simply with Hyperterminal ... i Can't find where is the problem ...
 
 
Any Help, please ?
 
Thanks a lot


#2 JoopC

JoopC

    Advanced Member

  • Members
  • PipPipPip
  • 148 posts

Posted 12 January 2016 - 07:48 PM

Here you can find a very good example of a visual basic client-server application on codeplex.

edit:

here you can find more examples:
https://netduinohelpers.codeplex.com/

#3 claudio.serio

claudio.serio

    Member

  • Members
  • PipPip
  • 25 posts

Posted 13 January 2016 - 09:06 AM

Thanks for reply .... but everyone can give a link .... i don't need a link.

 

I need a help to understand. Have you tried this code ? 

There're no problem with this code, indeed it works properly on a PC. I'd want to know why it doesn't work on N3.

So ... if someone should want help me .... i need that he tries this code.

 

Thank you



#4 JoopC

JoopC

    Advanced Member

  • Members
  • PipPipPip
  • 148 posts

Posted 14 January 2016 - 07:41 AM

Thank you, but I am not everyone.

I am not a teacher but (without insulting) the code you have written looks like beginners code and so much wrong, so the easiest way to learn yourself .netMF VB you'll need to read and understand examples from other and see the differences.

#5 claudio.serio

claudio.serio

    Member

  • Members
  • PipPip
  • 25 posts

Posted 14 January 2016 - 09:25 AM

Magically i può the same code on a N2+ and workshop fine ... so there wasn't errors. So ... again ... have you tried or not ?





Also tagged with one or more of these keywords: TCP, Socket.Send

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.