Public Class Form1
Dim Listener As New TcpListener(8000)
Dim Client As TcpClient
Private Sub _FormClosing() Handles Me.FormClosing
Listener.Stop()
End Sub
Private Sub _Load() Handles MyBase.Load
Timer1.Start()
Listener.Start()
End Sub
Private Sub _Tick() Handles Timer1.Tick
Dim Message As String
Dim nStart As Integer
Dim nLast As Integer
If Listener.Pending = True Then
Message = ""
Client = Listener.AcceptTcpClient()
Dim Reader As New StreamReader(Client.GetStream())
While Reader.Peek > -1
Message &= Convert.ToChar(Reader.Read()).ToString
End While
If Message.Contains("</>") Then
nStart = InStr(Message, "</>") + 4
nLast = InStr(Message, "<\>")
Message = Mid(Message, nStart, nLast - nStart)
End If
Label1.Text = Message
End If
End Sub
End Class
*전송코드*
Option Explicit On
Imports System.IO
Imports System.Net.Sockets
Public Class Form1
Dim Client As TcpClient
Private Sub btnClick() Handles Button1.Click
Try
Client = New TcpClient("127.0.0.1", 8000)
Dim Writer As New StreamWriter(Client.GetStream())
Writer.Write("</> " & TextBox1.Text & " <\>")
Writer.Flush()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class