Imports System.Net.Sockets Imports System.Text Public Class Form1 Public Shared serverSocket As New TcpListener(System.Net.IPAddress.Any, 8888) Public Shared requestCount As Integer Public Shared clientSocket As TcpClient Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load serverSocket.Start() TextBox1.AppendText("Started..") clientSocket = serverSocket.AcceptTcpClient() TextBox1.AppendText("Accept connection from client..") requestCount = 0 While (clientSocket.Connected = True) Try requestCount = requestCount + 1 Dim networkStream As NetworkStream = clientSocket.GetStream() Dim bytesFrom(10024) As Byte networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize)) Dim dataFromClient As String = System.Text.Encoding.ASCII.GetString(bytesFrom) dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$")) TextBox1.AppendText(dataFromClient) Dim serverResponse As String = "Server response " + Convert.ToString(requestCount) Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(serverResponse) networkStream.Write(sendBytes, 0, sendBytes.Length) networkStream.Flush() TextBox1.AppendText("serverResponse") Catch ex As Exception MsgBox(ex.ToString) End Try End While End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click End Sub End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)