Anfänger Webserver mit Wiznet 5200

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    Aufgrund technischer Veränderungen ist der Mailverkehr innerhalb des Forums (Private Nachrichten) nur noch eingeschränkt möglich. Die Einschränkung ist notwendig, um zusätzliche Betriebskosten für das Forum zu vermeiden. Näheres zu den Hintergründen im Thread "Aktuelles zum Forum".Wir bitten um Verständnis.

    Hinweis kann nach Kenntnisnahme deaktiviert werden!

    • Pluto25 schrieb:

      Meldet er 74 oder 47 dann 27 und dann - ohne Error weiß man wie das die Verbindung weg ist? Bzw wie (vom wem/von wo aus) wird sie wieder aufgebaut?
      -Das ganze mal mit Wireshark betrachtet?
      Noch mal:
      ich baue Manuell die Verbindung auf und bekomme die ersten zwei TCPWRITESTR
      Trenne dann die Verbindung manuell und baue sie wieder auf manuell. Und dann bekomme ich alle drei TCPWRITESTR geliefert.
    • Aber du musst verstehen, dass das alles für einen "Außenstehenden" zu abstrakt ist.
      Niemand kennt deine VB Software und deinen aktuellen Bascom Code... das ist wie Glaskugel lesen.

      Der Hinweis auf Wireshark ist übrigens goldrichtig! Wenn ich da Zweifel habe, werfe ich Wireshark an und schau in die Pakete, was da abläuft.
      Ich denke, du hast ein Problem damit, dass der Verbindungsstatus unklar ist.
      Code first, think later - Natural programmer :D
    • Pluto25 schrieb:

      Wir sprechen aneinander vorbei: Trennen wie? Mit dem wiz, Mit dem Pc ? Den kabel ziehen? Die Friztzbox ausschalten? Einer Kettensäge? Verbinden wie nur einem sagen verbinde oder beiden oder nur Kabel einstöpseln ? Ich vermute das Problem beim PC - gehts ohne Fritzbox? (Vorsicht evt anderes Kabel nötig)
      Hallo,

      hat zwar etwas lange gedauert, war nicht im Lande.
      @Pluto25 Trennen und verbinden tue ich immer mit der Software
      siehe unten:

      VB.NET Code zum Verbinden

      Quellcode

      1. Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
      2. 'connect to tcp server
      3. clsTcp.IpAddr = txtIp.Text
      4. clsTcp.Port = CInt(cobPort.Text)
      5. If clsTcp.Connect Then
      6. lblSockStat.Text = "Socket Open"
      7. btnConnect.Enabled = False
      8. btnDisconnect.Enabled = True
      9. txtIp.Enabled = False
      10. cobPort.Enabled = False
      11. chkTimeOut.Enabled = True
      12. DomainUpDown1.Enabled = True
      13. End If
      14. End Sub
      Alles anzeigen

      Trennen:

      Quellcode

      1. Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
      2. 'disconnect from server
      3. If clsTcp.Disconnect Then
      4. txtRcv.Text = "No device"
      5. lblSockStat.Text = "Socket Closed"
      6. btnConnect.Enabled = True
      7. btnDisconnect.Enabled = False
      8. txtIp.Enabled = True
      9. cobPort.Enabled = True
      10. chkTimeOut.Enabled = False
      11. DomainUpDown1.Enabled = False
      12. AllCheckBoxEmpty()
      13. End If
      14. End Sub
      Alles anzeigen
      und hier noch mal der Code im Klasse TCPClient:

      Quellcode

      1. Imports System.Net.Sockets
      2. Imports System.Text
      3. Imports System.Net
      4. Public Class TCPClient
      5. 'Dim tcpClnt As New System.Net.Sockets.TcpClient
      6. Dim tcpClnt As System.Net.Sockets.TcpClient
      7. Dim networkStream As NetworkStream
      8. Public Event Receive(ByVal msg As String)
      9. Public Event Disconnected()
      10. Dim mIpAddr As String
      11. Dim mPort As Integer
      12. Dim mMessage As String
      13. Dim ctThread As Threading.Thread
      14. Dim infiniteCounter As Integer
      15. Dim CloseStream As Boolean
      16. Private arData(1024) As Byte
      17. Private objText As New StringBuilder()
      18. Sub New()
      19. End Sub
      20. Public Property IpAddr() As String
      21. Get
      22. Return mIpAddr
      23. End Get
      24. Set(ByVal value As String)
      25. mIpAddr = value
      26. End Set
      27. End Property
      28. Public Property Port() As Integer
      29. Get
      30. Return mPort
      31. End Get
      32. Set(ByVal value As Integer)
      33. mPort = value
      34. End Set
      35. End Property
      36. Public ReadOnly Property IsOpen() As Boolean
      37. Get
      38. If tcpClnt Is Nothing Then
      39. Return False
      40. Else
      41. Return tcpClnt.Connected
      42. End If
      43. End Get
      44. End Property
      45. Public ReadOnly Property Message() As String
      46. Get
      47. Return mMessage
      48. End Get
      49. End Property
      50. Public ReadOnly Property LocalIp() As String
      51. Get
      52. Dim strHostName As String = Dns.GetHostName
      53. 'using host name, get the IP address list..
      54. 'Dim ipEntry As IPHostEntry = Dns.GetHostByName(strHostName)
      55. Dim ipEntry As IPHostEntry = Dns.GetHostEntry(strHostName)
      56. Dim addr() As IPAddress = ipEntry.AddressList
      57. Return addr(0).ToString
      58. End Get
      59. End Property
      60. Public Function Connect() As Boolean
      61. Try
      62. 'Create a new TcpClient class
      63. tcpClnt = New System.Net.Sockets.TcpClient
      64. 'Connect to the TCP Server
      65. tcpClnt.Connect(mIpAddr, mPort)
      66. 'Original use threading to wait for receive (getMessage)
      67. 'CloseStream = False
      68. 'ctThread = New Threading.Thread(AddressOf getMessage)
      69. 'ctThread.Start()
      70. 'use Getstream to wait for receive (Rcv)
      71. networkStream = tcpClnt.GetStream()
      72. tcpClnt.GetStream.BeginRead(arData, 0, 1024, AddressOf Rcv, Nothing)
      73. Return True
      74. Catch ex As Exception
      75. Return False
      76. End Try
      77. End Function
      78. Public Function Disconnect() As Boolean
      79. Try
      80. 'CloseStream = True
      81. 'networkStream.Close()
      82. tcpClnt.GetStream.Close()
      83. tcpClnt.Close()
      84. Return True
      85. Catch ex As Exception
      86. Return False
      87. End Try
      88. End Function
      89. Public Function Send(ByVal txtMsg As String) As Boolean
      90. Try
      91. 'Original use NetworkStream to write data
      92. 'Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes(txtMsg & vbCrLf)
      93. 'networkStream.Write(outStream, 0, outStream.Length)
      94. 'networkStream.Flush()
      95. 'use GetStream
      96. txtMsg &= vbCrLf
      97. tcpClnt.GetStream.Write(Encoding.ASCII.GetBytes(txtMsg), 0, Encoding.ASCII.GetBytes(txtMsg).Length)
      98. Catch ex As Exception
      99. tcpClnt.Close()
      100. RaiseEvent Disconnected()
      101. End Try
      102. End Function
      103. Public Sub getMessage()
      104. Try
      105. For infiniteCounter = 1 To 2
      106. infiniteCounter = 1
      107. 'check to see if we still have a connection
      108. If tcpClnt.Connected = False Then
      109. tcpClnt.Close()
      110. RaiseEvent Disconnected()
      111. Exit For
      112. End If
      113. 'open a network stream
      114. networkStream = tcpClnt.GetStream()
      115. Dim buffSize As Integer
      116. Dim inStream(10024) As Byte
      117. buffSize = tcpClnt.ReceiveBufferSize
      118. 'wait for data to be received
      119. While networkStream.DataAvailable = False
      120. 'see if we can receive the data
      121. If networkStream.CanRead = False Then
      122. tcpClnt.Close()
      123. RaiseEvent Disconnected()
      124. Exit For
      125. End If
      126. 'are we still connected?
      127. If tcpClnt.Connected = False Then
      128. tcpClnt.Close()
      129. RaiseEvent Disconnected()
      130. Exit For
      131. End If
      132. 'main program says disconnect
      133. If CloseStream = True Then
      134. Exit For
      135. End If
      136. Threading.Thread.Sleep(200)
      137. End While
      138. 'data is ready
      139. 'read the data
      140. networkStream.Read(inStream, 0, buffSize)
      141. Dim returndata As String = System.Text.Encoding.ASCII.GetString(inStream)
      142. mMessage = returndata
      143. 'raise the receive event
      144. RaiseEvent Receive(mMessage)
      145. Threading.Thread.Sleep(200)
      146. Next
      147. Catch ex As Exception
      148. tcpClnt.Close()
      149. RaiseEvent Disconnected()
      150. End Try
      151. End Sub
      152. Private Sub Rcv(ByVal ar As IAsyncResult)
      153. ' Start the data receiving process
      154. Dim intCount As Integer
      155. Try
      156. 'data ready end the read
      157. SyncLock tcpClnt.GetStream
      158. intCount = tcpClnt.GetStream.EndRead(ar)
      159. End SyncLock
      160. If intCount < 1 Then
      161. RaiseEvent Disconnected()
      162. Exit Sub
      163. End If
      164. 'put the byte daa into a string
      165. BuildString(arData, 0, intCount)
      166. SyncLock tcpClnt.GetStream
      167. tcpClnt.GetStream.BeginRead(arData, 0, 1024, AddressOf Rcv, Nothing)
      168. End SyncLock
      169. Catch e As Exception
      170. RaiseEvent Disconnected()
      171. End Try
      172. End Sub
      173. Private Sub BuildString(ByVal Bytes() As Byte, ByVal offset As Integer, ByVal count As Integer)
      174. Dim intIndex As Integer
      175. Dim txt As String
      176. objText = New StringBuilder
      177. For intIndex = offset To offset + count - 1
      178. txt = ChrW(Bytes(intIndex))
      179. objText.Append(txt)
      180. Next
      181. RaiseEvent Receive(objText.ToString)
      182. End Sub
      183. End Class
      Alles anzeigen

      six1 schrieb:

      Warum sendest du zweimal crlf ?
      habe ich abgeändert siehe unten:

      BASCOM-Quellcode

      1. If Flags.idx = 0 Then
      2. Flags.idx = 1
      3. Result = Tcpwritestr(idx , Ss , 0 )
      4. Print "Erste " ; Result
      5. Result = Tcpwritestr(idx , T , 0 )
      6. Print "Zweite " ; Result
      7. Result = Tcpwritestr(idx , U , 0)
      8. Print "Dritte " ; Result
      9. End If
      hat aber leider nichts gebracht :)
    • [​Gelöst]

      [Gelöst]

      Ich habe aus 3 Strings nur noch einen draus gemacht und es funktioniert.
      Ich bin zufrieden damit und der Laufschrift auch :)

      BASCOM-Quellcode

      1. Case Sock_established
      2. Ss = "DeviceName|Laufschrift ist verbunden mit |" + Str(deviceadresse) + "LEDStatus|" + Str(deviceadresse) + "|" + Channel1 + "|" + Channel2 + "|" + Channel3 + "|" + Channel4 + "|" + Channel5 + "|" + Channel6 + "|" + Channel7 + "|" + Channel8 + "TimeOutTriggert|" + Str(deviceadresse) + "|" + Str(timeout_ausgeloest)
      3. If Flags.idx = 0 Then
      4. Flags.idx = 1
      5. Result = Tcpwritestr(idx , Ss , 255 )
      6. End If
    • Schön das es funktioniert. Dennoch wäre interessant zu wissen was da schief lief. Beim trennen schickt er ein Fin raus und bekommt ein Ack zurück. Beim Wiederverbinden bekam er dann die noch wartenden Daten - dann hat er sie irgend warum vorher nicht bekommen.
      Mein "Kerlchen" sendet immer nur ein Packet nach Anfrage. Ich muß mal probieren was passiert wenn er ein weiteres unangefragt senden würde. Müßte dann nicht das erste wenigstens das Flag "Fragmentiert" haben? Das wiederum kann der Wiz nicht wissen - müsste ihm auch irgendwie mitgeteilt werden.
    • Nun bin ich aber deprimiert.
      Es kann doch nicht sein, das in den Gesamten Qullcode der TCPWRITESTR nur zwei mal vorkommen darf?!?!

      Sobald ich einen dritten habe, bekomme ich die Daten nicht.

      Was ist hier schief?

      Kann es sein, das dieser Code gar net mit dem W5500 kompatible ist?

      Hier der Gesamte code im Überblick

      BASCOM-Quellcode

      1. $regfile = "m32def.dat" ' specify the used micro
      2. $crystal = 16000000 ' used crystal frequency
      3. $baud = 19200 ' use baud rate
      4. $hwstack = 128 ' default use 32 for the hardware stack
      5. $swstack = 128 ' default use 10 for the SW stack
      6. $framesize = 128 ' default use 40 for the frame space
      7. $lib "datetime.lbx"
      8. Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
      9. Spiinit
      10. Enable Interrupts
      11. W5500_nreset Alias Portd.7
      12. Config Pind.7 = Output
      13. Reset W5500_nreset
      14. Waitms 5
      15. Set W5500_nreset
      16. Waitms 500 'Diese Zeitinterval muss mindestens 300ms sein, damit das W5500 initialisieren kann
      17. Config Tcpip = Noint , Mac = 0.8.&Hdc.77.05.11 , Ip = 192.168.178.29 , Submask = 255.255.255.0 , Gateway = 192.168.178.1 , Localport = 2005 , Chip = W5500 , Spi = 1 , Cs = Portb.4
      18. Config Portc = Output
      19. '-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Config für den Power LED Grün LED
      20. Config Portd.2 = Output 'PIN 26 am AVR
      21. Betriebsled Alias Portd.2
      22. Betriebsled = 1
      23. '-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Config für den DATA I/O Blau LED
      24. Config Portd.3 = Output
      25. Interfaceactivated Alias Portd.3 'Zeigt anhand der LED (Interface Activated) ob eine Kommunikation über das USB statt findet.
      26. Interfaceactivated = 1
      27. '-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Config für den TimeOut Orange LED
      28. Config Portd.6 = Output
      29. Timeoutled Alias Portd.6
      30. Timeoutled = 1
      31. '-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Config für den ERROR Rot LED
      32. Config Portd.5 = Output
      33. Error Alias Portd.5
      34. Error = 1
      35. '-------------------------------------- WATCHDOG FÜR DEN INTERNEN SOFTWARE CHRASH --------------------------------------------
      36. Config Watchdog = 2048 'Timeout = 2 Sekunden
      37. '-------------------------------------- AUSGANGS VARIABLEN --------------------------------------------------------------------
      38. Dim Bclient As Byte ' socket number
      39. Dim Idx As Byte
      40. Dim Result1 As Word , Result2 As Word
      41. Dim S As String * 80
      42. Dim Ss As String * 80
      43. Dim Y As String * 80
      44. Dim Flags As Byte
      45. Dim Peer As Long
      46. Dim A As String * 15
      47. Dim Tmp As Byte
      48. Dim Command_array(14) As String * 15
      49. Dim Channel1 As String * 3
      50. Dim Channel2 As String * 3
      51. Dim Channel3 As String * 3
      52. Dim Channel4 As String * 3
      53. Dim Channel5 As String * 3
      54. Dim Channel6 As String * 3
      55. Dim Channel7 As String * 3
      56. Dim Channel8 As String * 3
      57. Dim Ausgang1 As String * 3
      58. Dim Ausgang2 As String * 3
      59. Dim Ausgang3 As String * 3
      60. Dim Ausgang4 As String * 3
      61. Dim Ausgang5 As String * 3
      62. Dim Ausgang6 As String * 3
      63. Dim Ausgang7 As String * 3
      64. Dim Ausgang8 As String * 3
      65. Dim Timeout_ausgeloest As Byte
      66. Dim Timerwert As Word
      67. '-------------------------------------- LED SELBSTTEST 1 SEKUNDE AN UND AUS --------------------------------------------
      68. Wait 1
      69. Interfaceactivated = 0
      70. Timeoutled = 0
      71. Error = 0
      72. Do
      73. Start Watchdog
      74. For Idx = 0 To 3
      75. Result1 = Socketstat(idx , 0) ' get status
      76. Select Case Result1
      77. Case Sock_established
      78. Ss = "FirstConnect|Laufschrift ist verbunden mit |" + Str(deviceadresse) + "|" + Channel1 + "|" + Channel2 + "|" + Channel3 + "|" + Channel4 + "|" + Channel5 + "|" + Channel6 + "|" + Channel7 + "|" + Channel8 + "|" + Str(timeout_ausgeloest)
      79. If Flags.idx = 0 Then
      80. Flags.idx = 1
      81. Result1 = Tcpwritestr(idx , Ss , 255 )
      82. End If
      83. Result1 = Socketstat(idx , Sel_recv) ' get number of bytes waiting
      84. If Result1 > 0 Then
      85. Do
      86. Result1 = Tcpread(idx , S)
      87. Tmp = Split(s , Command_array(1) , "|")
      88. If Command_array(1) = Str(deviceadresse) Then
      89. Interfaceactivated = 1 'Blaue LED einschalten
      90. Select Case Command_array(2) ' Daten Art
      91. Case "1" 'LED MAtrix Anzeige
      92. Channel1 = Command_array(3)
      93. Channel2 = Command_array(4)
      94. Channel3 = Command_array(5)
      95. Channel4 = Command_array(6)
      96. Channel5 = Command_array(7)
      97. Channel6 = Command_array(8)
      98. Channel7 = Command_array(9)
      99. Channel8 = Command_array(10)
      100. Portc = Val(command_array(3))
      101. Case "0" 'TimeOut
      102. If Command_array(14) = "1" Then
      103. Config Timer1 = Timer , Prescale = 1024
      104. Select Case Val(command_array(13))
      105. Case 0 : Timerwert = 22567 'Timer auf 5.5s. setzen
      106. Case 1 : Timerwert = 14755 'Timer auf 6.5s. setzen
      107. Case 2 : Timerwert = 6942 'Timer auf 7.5s. setzen
      108. Case 3 : Timerwert = 692 'Timer auf 8.0s. setzen
      109. End Select
      110. End If
      111. If Command_array(12) = "1" Then 'aktivieren
      112. Start Timer1 'TimerOut aktivieren
      113. Timer1 = Timerwert 'Timer auf eine Bestimte Zeit setzen
      114. Isttimeraktiviert = 1
      115. Elseif Command_array(12) = "0" Then
      116. Stop Timer1 'TimeOut deaktivieren
      117. Isttimeraktiviert = 0 'Variable wieder auf NULL setzen
      118. Timeoutled = 0 'Orange LED ausschalten
      119. End If
      120. If Command_array(11) = "1" And Isttimeraktiviert = 1 Then 'Wenn PING ankommt
      121. Timer1 = Timerwert 'beginnt der Zähler von Vorne an zu zählen
      122. Timeoutled = 0 'Orange LED ausschalten falls evtl. eingeschaltet wird warum auch immer
      123. End If
      124. If Command_array(11) = "1" And Command_array(12) = "0" And Command_array(13) = "0" And Command_array(14) = "0" Then
      125. Timeout_ausgeloest = 0
      126. A = "TimeOut|" + Str(deviceadresse)
      127. Result1 = Tcpwritestr(idx , A , 255 )
      128. End If
      129. Case Else
      130. End Select
      131. Interfaceactivated = 0
      132. End If
      133. Reset Watchdog
      134. Loop Until S = ""
      135. End If
      136. Y = "LEDMatrixMM|" + Str(deviceadresse) + "|" + Ausgang1 + "|" + Ausgang2 + "|" + Ausgang3 + "|" + Ausgang4 + "|" + Ausgang5 + "|" + Ausgang6 + "|" + Ausgang7 + "|" + Ausgang8 + "|" + Channel1 + "|" + Channel2 + "|" + Channel3 + "|" + Channel4 + "|" + Channel5 + "|" + Channel6 + "|" + Channel7 + "|" + Channel8 + "|" + Str(timeout_ausgeloest)
      137. Result1 = Tcpwritestr(idx , Y , 255 )
      138. Case Sock_close_wait
      139. Closesocket Idx
      140. Case Sock_closed
      141. Bclient = Getsocket(idx , Sock_stream , 2005 , 0) ' get socket for server mode, specify port 5000
      142. Socketlisten Idx
      143. Flags.idx = 0
      144. Case Sock_listen
      145. Case Else
      146. End Select
      147. Next
      148. Reset Watchdog
      149. Loop
      150. '################################################### WENN TIMEOUT AUSLÖST ##########################################################################
      151. Timerroutine:
      152. Config Timer1 = Timer , Prescale = 256 'Wenn Timeout auslöst:
      153. Timer1 = 59286 'Timer auf neuen Startwert 210ms einstellen
      154. Toggle Timeoutled
      155. Portc = 0
      156. Timeout_ausgeloest = 1 'Bei dieses Gerät hat der Timeout ausgelöst, da wird einfach die Adresse gesendet
      157. Print "TimeOut hat ausgelöst"
      158. Return
      159. '################################################ ENDE TIMEOUT AUSLÖSUNG ############################################################################
      160. End
      Alles anzeigen

      sobald ich hier den TCPWRITESTR habe...

      If Command_array(11) = "1" And Command_array(12) = "0" And Command_array(13) = "0" And Command_array(14) = "0" Then

      Timeout_ausgeloest = 0

      A = "TimeOut|" + Str(deviceadresse)
      Result1 = Tcpwritestr(idx , A , 255 ) '<---- Diese ist zu viel für den Gesamten Code, warum auch immer


      End If

      hoffe einer von euch Blickt da durch und kann mir weiter helfen.

      danke im Voraus
      Katip





      Nochwas:

      Im Code habe ich den Baudrate wie folgt eingestellt:

      BASCOM-Quellcode

      1. $regfile = "m32def.dat" ' specify the used micro
      2. $crystal = 16000000 ' used crystal frequency
      3. $baud = 19200 ' use baud rate
      und im HyperTerminal muss ich auf 9600 gehen, damit ich was sehen und lesen kann.
      Bei alle anderen wird mir komische Buchstaben geliefert.

      Woran kann das liegen?

      bascom1.PNG

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von katipefendi ()

    • Wo hast du die Hardware zur Flusssteuerung? Das sind doch normal 2 Leitungen zusätzlich, ready_to_send und sowas ähnliches.

      Edit:heißt request to send :S
      mikrocontroller.net/articles/RS-232#Flusssteuerung
      Raum für Notizen

      -----------------------------------------------------------------------------------------------------

      -----------------------------------------------------------------------------------------------------

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von tschoeatsch ()

    • Das scheint so nicht zu stimmen. Ich habe eben mal einfach "drauflosgeplappert "und der winsock nahm alles an (bis das Programm abschmierte weil es unerwartete Daten bekam - ein ljfhghd ist einfach keine gültige integer ;-).) Allerdings konnte ich nicht beliebig schnell nacheinander senden. Mein ESP03-Modul verschluckte Daten wenn sie zu schnell hintereinander kamen. (bzw meldete Error). Möglicherweise ist es Deinem Wiz zu schnell zwei Pakete zu senden die nur µs auseinanderliegen. Womöglich geht's das zweite auf einen anderen channel zu senden oder ein waiteinbischen einzubauen.
    • sandis schrieb:

      @katipefendi : can u share vb project files to test with wiznet ??

      thanks
      Hallo,

      BASCOM-Quellcode

      1. Imports System
      2. Imports System.IO
      3. Imports System.Net
      4. Imports System.Net.Sockets
      5. Imports System.Text
      6. Imports Microsoft.VisualBasic
      7. Class MyTcpListener
      8. Sub Main()
      9. Console.WriteLine("Bitte geben sie die Locale IP ein: ")
      10. connect(Console.ReadLine())
      11. End Sub
      12. Sub connect(ByVal ip As String)
      13. Dim server As TcpListener
      14. server = Nothing
      15. Try
      16. ' Set the TcpListener on port 13000.
      17. Dim port As Int32 = 1234
      18. Dim localAddr As IPAddress = IPAddress.Parse(ip)
      19. server = New TcpListener(localAddr, port)
      20. ' Start listening for client requests.
      21. server.Start()
      22. ' Buffer for reading data
      23. Dim bytes(1024) As Byte
      24. Dim data As String = Nothing
      25. ' Enter the listening loop.
      26. While True
      27. Console.Write("Waiting for a connection... ")
      28. ' Perform a blocking call to accept requests.
      29. ' You could also user server.AcceptSocket() here.
      30. Dim client As TcpClient = server.AcceptTcpClient()
      31. Console.WriteLine("Connected!")
      32. data = Nothing
      33. ' Get a stream object for reading and writing
      34. Dim stream As NetworkStream = client.GetStream()
      35. Dim i As Int32
      36. ' Loop to receive all the data sent by the client.
      37. i = stream.Read(bytes, 0, bytes.Length)
      38. While (i <> 0)
      39. ' Translate data bytes to a ASCII string.
      40. data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
      41. Console.WriteLine("Received: {0}", data)
      42. ' Hier hast du den empfangenen string data
      43. If data = ....
      44. 'Anschließend gibst du die antwort:
      45. data = "Button1.text = hehehe"
      46. Dim msg As Byte() = System.Text.Encoding.ASCII.GetBytes(data)
      47. stream.Write(msg, 0, msg.Length)
      48. Console.WriteLine("Sent: {0}", data)
      49. i = stream.Read(bytes, 0, bytes.Length)
      50. End While
      51. ' Shutdown and end connection
      52. client.Close()
      53. End While
      54. Catch e As SocketException
      55. Console.WriteLine("SocketException: {0}", e)
      56. Finally
      57. server.Stop()
      58. End Try
      59. Console.WriteLine(ControlChars.Cr + "Hit enter to continue....")
      60. Console.Read()
      61. End Sub
      62. End Class 'MyTcpListener
      Alles anzeigen