<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.vbex.ru/index.php?action=history&amp;feed=atom&amp;title=VB.Net_Tutorial%2FSocket_Network%2FSocket_Server</id>
		<title>VB.Net Tutorial/Socket Network/Socket Server - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.vbex.ru/index.php?action=history&amp;feed=atom&amp;title=VB.Net_Tutorial%2FSocket_Network%2FSocket_Server"/>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net_Tutorial/Socket_Network/Socket_Server&amp;action=history"/>
		<updated>2026-04-05T07:13:29Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.vbex.ru/index.php?title=VB.Net_Tutorial/Socket_Network/Socket_Server&amp;diff=3516&amp;oldid=prev</id>
		<title> в 16:40, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net_Tutorial/Socket_Network/Socket_Server&amp;diff=3516&amp;oldid=prev"/>
				<updated>2010-05-26T16:40:30Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 16:40, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.vbex.ru/index.php?title=VB.Net_Tutorial/Socket_Network/Socket_Server&amp;diff=3517&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.vbex.ru/index.php?title=VB.Net_Tutorial/Socket_Network/Socket_Server&amp;diff=3517&amp;oldid=prev"/>
				<updated>2010-05-26T12:55:52Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Date time server based on System.Net.Sockets.Socket==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;vbnet&amp;quot;&amp;gt;Imports System.Net&lt;br /&gt;
Imports System.Net.Sockets&lt;br /&gt;
Imports System.Threading&lt;br /&gt;
Imports System.Text&lt;br /&gt;
Public Class DateTimeServer&lt;br /&gt;
  Public Shared Sub Main()&lt;br /&gt;
    Dim serverSocket As System.Net.Sockets.Socket&lt;br /&gt;
    Try&lt;br /&gt;
      Dim hostname As String = Dns.GetHostName()&lt;br /&gt;
      Dim serverIP As IPAddress = Dns.Resolve(hostname).AddressList(0)&lt;br /&gt;
      Dim Port As String = &amp;quot;13&amp;quot;&lt;br /&gt;
      Dim serverhost As New IPEndPoint(serverIP, Int32.Parse(Port))&lt;br /&gt;
      serverSocket = New Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp)&lt;br /&gt;
      serverSocket.Bind(serverhost)&lt;br /&gt;
      serverSocket.Listen(50)&lt;br /&gt;
      Console.WriteLine(&amp;quot;DateTime server started at: &amp;quot; + serverhost.Address.ToString() + &amp;quot;:&amp;quot; + Port)&lt;br /&gt;
      Dim lc As New ListenClient(serverSocket)&lt;br /&gt;
      Dim serverthread As New Thread(New ThreadStart(AddressOf lc.ServerThreadProc))&lt;br /&gt;
      serverthread.Start()&lt;br /&gt;
    Catch ex As Exception&lt;br /&gt;
      Console.WriteLine(ex.StackTrace.ToString())&lt;br /&gt;
    End Try&lt;br /&gt;
  End Sub&lt;br /&gt;
End Class&lt;br /&gt;
&lt;br /&gt;
Public Class ListenClient&lt;br /&gt;
  Private serverSocket As System.Net.Sockets.Socket&lt;br /&gt;
&lt;br /&gt;
  Public Sub New(ByVal serverSocket As System.Net.Sockets.Socket)&lt;br /&gt;
    Me.serverSocket = serverSocket&lt;br /&gt;
  End Sub&lt;br /&gt;
  Public Sub ServerThreadProc()&lt;br /&gt;
    Dim clientSocket As System.Net.Sockets.Socket&lt;br /&gt;
    Try&lt;br /&gt;
      While (True)&lt;br /&gt;
        clientSocket = serverSocket.Accept()&lt;br /&gt;
        Dim clientInfo As IPEndPoint = CType( _&lt;br /&gt;
            clientSocket.RemoteEndPoint, _&lt;br /&gt;
            IPEndPoint)&lt;br /&gt;
        Dim serverInfo As IPEndPoint = CType( _&lt;br /&gt;
            serverSocket.LocalEndPoint, _&lt;br /&gt;
            IPEndPoint)&lt;br /&gt;
        Console.WriteLine(&amp;quot;Client: &amp;quot; + clientInfo.Address.ToString() + &amp;quot;:&amp;quot; + clientInfo.Port.ToString())&lt;br /&gt;
        Console.WriteLine(&amp;quot;Server: &amp;quot; + serverInfo.Address.ToString() + &amp;quot;:&amp;quot; + serverInfo.Port.ToString())&lt;br /&gt;
        Dim strDate As String = DateTime.Now.ToShortDateString() + &amp;quot; &amp;quot; + DateTime.Now.ToLongTimeString()&lt;br /&gt;
        Dim byteDateLine() As Byte = Encoding.ASCII.GetBytes(strDate.ToCharArray())&lt;br /&gt;
        clientSocket.Send(byteDateLine, byteDateLine.Length, SocketFlags.None)&lt;br /&gt;
        Console.WriteLine(&amp;quot;To Client: &amp;quot; + clientInfo.Address.ToString() + &amp;quot;:&amp;quot; + clientInfo.Port.ToString() + &amp;quot;: &amp;quot; + strDate)&lt;br /&gt;
        clientSocket.Shutdown(SocketShutdown.Both)&lt;br /&gt;
        clientSocket.Close()&lt;br /&gt;
      End While&lt;br /&gt;
    Catch ex As Exception&lt;br /&gt;
      Console.WriteLine(ex.StackTrace.ToString())&lt;br /&gt;
      If clientSocket.Connected Then&lt;br /&gt;
        clientSocket.Close()&lt;br /&gt;
      End If&lt;br /&gt;
    End Try&lt;br /&gt;
  End Sub&lt;br /&gt;
End Class&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Socket server==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;vbnet&amp;quot;&amp;gt;Imports System.Threading&lt;br /&gt;
Imports System.Net&lt;br /&gt;
Imports System.Net.Sockets&lt;br /&gt;
&lt;br /&gt;
Public Class ServerSocket&lt;br /&gt;
  Public Shared Sub Main()&lt;br /&gt;
    Try&lt;br /&gt;
      Dim serverSocket As New Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp)&lt;br /&gt;
      Dim serverIP As IPAddress = IPAddress.Parse(&amp;quot;127.0.0.1&amp;quot;)&lt;br /&gt;
      Dim Port As String = &amp;quot;80&amp;quot;&lt;br /&gt;
      Dim serverhost As New IPEndPoint(serverIP, Int32.Parse(Port))&lt;br /&gt;
      serverSocket.Bind(serverhost)&lt;br /&gt;
      serverSocket.Listen(50)&lt;br /&gt;
      Console.WriteLine(&amp;quot;Server started at: &amp;quot; + serverIP.ToString() + &amp;quot;:&amp;quot; + Port)&lt;br /&gt;
      Dim lc As New ListenClient(serverSocket)&lt;br /&gt;
      Dim serverthread As New Thread(New ThreadStart(AddressOf lc.ServerThreadProc))&lt;br /&gt;
      serverthread.Start()&lt;br /&gt;
    Catch ex As Exception&lt;br /&gt;
      Console.WriteLine(ex.StackTrace.ToString())&lt;br /&gt;
    End Try&lt;br /&gt;
  End Sub&lt;br /&gt;
End Class&lt;br /&gt;
&lt;br /&gt;
Public Class ListenClient&lt;br /&gt;
  Private serverSocket As System.Net.Sockets.Socket&lt;br /&gt;
  Private clientSocket As System.Net.Sockets.Socket&lt;br /&gt;
  Public Sub New(ByVal serverSocket As System.Net.Sockets.Socket)&lt;br /&gt;
    Me.serverSocket = serverSocket&lt;br /&gt;
  End Sub&lt;br /&gt;
  Public Sub ServerThreadProc()&lt;br /&gt;
    Do While True&lt;br /&gt;
      Try&lt;br /&gt;
        Dim clientSocket As Socket = serverSocket.Accept()&lt;br /&gt;
        Dim clientInfo As IPEndPoint = CType( _&lt;br /&gt;
            clientSocket.RemoteEndPoint, _&lt;br /&gt;
            IPEndPoint)&lt;br /&gt;
        Dim serverInfo As IPEndPoint = CType( _&lt;br /&gt;
            serverSocket.LocalEndPoint, _&lt;br /&gt;
            IPEndPoint)&lt;br /&gt;
        Console.WriteLine(&amp;quot;Client: &amp;quot; + clientInfo.Address.ToString() + &amp;quot;:&amp;quot; + clientInfo.Port.ToString())&lt;br /&gt;
        Console.WriteLine(&amp;quot;Server: &amp;quot; + serverInfo.Address.ToString() + &amp;quot;:&amp;quot; + serverInfo.Port.ToString())&lt;br /&gt;
      Catch ex As Exception&lt;br /&gt;
        Console.WriteLine(ex.StackTrace.ToString())&lt;br /&gt;
      End Try&lt;br /&gt;
    Loop&lt;br /&gt;
  End Sub&lt;br /&gt;
End Class&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Server started at: 127.0.0.1:80&lt;br /&gt;
^CTerminate batch job (Y/N)? n&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Socket Server with user interface==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;vbnet&amp;quot;&amp;gt;Imports System.Text&lt;br /&gt;
Imports System.Net.Sockets&lt;br /&gt;
Imports System.Threading&lt;br /&gt;
Imports System.Windows.Forms&lt;br /&gt;
public class SocketServerUI&lt;br /&gt;
   public Shared Sub Main&lt;br /&gt;
        Application.Run(New Form1)&lt;br /&gt;
   End Sub&lt;br /&gt;
End class&lt;br /&gt;
Public Class Form1&lt;br /&gt;
    Inherits System.Windows.Forms.Form&lt;br /&gt;
    Public Sub New()&lt;br /&gt;
        MyBase.New()&lt;br /&gt;
        InitializeComponent()&lt;br /&gt;
    End Sub&lt;br /&gt;
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)&lt;br /&gt;
        If disposing Then&lt;br /&gt;
            If Not (components Is Nothing) Then&lt;br /&gt;
                components.Dispose()&lt;br /&gt;
            End If&lt;br /&gt;
        End If&lt;br /&gt;
        MyBase.Dispose(disposing)&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private components As System.ruponentModel.IContainer&lt;br /&gt;
    Friend WithEvents btnListener As System.Windows.Forms.Button&lt;br /&gt;
    Friend WithEvents lblMessage As System.Windows.Forms.Label&lt;br /&gt;
    Friend WithEvents lblConnection As System.Windows.Forms.Label&lt;br /&gt;
    Friend WithEvents lblPort As System.Windows.Forms.Label&lt;br /&gt;
    Friend WithEvents txtPort As System.Windows.Forms.TextBox&lt;br /&gt;
    Friend WithEvents btnClose As System.Windows.Forms.Button&lt;br /&gt;
    Friend WithEvents txtContent As System.Windows.Forms.TextBox&lt;br /&gt;
    Friend WithEvents Label1 As System.Windows.Forms.Label&lt;br /&gt;
    Friend WithEvents btnWrite As System.Windows.Forms.Button&lt;br /&gt;
    &amp;lt;System.Diagnostics.DebuggerStepThrough()&amp;gt; Private Sub InitializeComponent()&lt;br /&gt;
        Me.btnListener = New System.Windows.Forms.Button()&lt;br /&gt;
        Me.lblMessage = New System.Windows.Forms.Label()&lt;br /&gt;
        Me.lblConnection = New System.Windows.Forms.Label()&lt;br /&gt;
        Me.lblPort = New System.Windows.Forms.Label()&lt;br /&gt;
        Me.txtPort = New System.Windows.Forms.TextBox()&lt;br /&gt;
        Me.btnClose = New System.Windows.Forms.Button()&lt;br /&gt;
        Me.txtContent = New System.Windows.Forms.TextBox()&lt;br /&gt;
        Me.Label1 = New System.Windows.Forms.Label()&lt;br /&gt;
        Me.btnWrite = New System.Windows.Forms.Button()&lt;br /&gt;
        Me.SuspendLayout()&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;btnListener&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.btnListener.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.btnListener.Location = New System.Drawing.Point(338, 28)&lt;br /&gt;
        Me.btnListener.Name = &amp;quot;btnListener&amp;quot;&lt;br /&gt;
        Me.btnListener.Size = New System.Drawing.Size(113, 32)&lt;br /&gt;
        Me.btnListener.TabIndex = 0&lt;br /&gt;
        Me.btnListener.Text = &amp;quot;Start Listening&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;lblMessage&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.lblMessage.BackColor = System.Drawing.Color.White&lt;br /&gt;
        Me.lblMessage.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.lblMessage.Location = New System.Drawing.Point(164, 80)&lt;br /&gt;
        Me.lblMessage.Name = &amp;quot;lblMessage&amp;quot;&lt;br /&gt;
        Me.lblMessage.Size = New System.Drawing.Size(389, 24)&lt;br /&gt;
        Me.lblMessage.TabIndex = 1&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;lblConnection&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.lblConnection.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.lblConnection.Location = New System.Drawing.Point(61, 80)&lt;br /&gt;
        Me.lblConnection.Name = &amp;quot;lblConnection&amp;quot;&lt;br /&gt;
        Me.lblConnection.Size = New System.Drawing.Size(93, 24)&lt;br /&gt;
        Me.lblConnection.TabIndex = 2&lt;br /&gt;
        Me.lblConnection.Text = &amp;quot;Connection Message&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;lblPort&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.lblPort.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.lblPort.Location = New System.Drawing.Point(41, 33)&lt;br /&gt;
        Me.lblPort.Name = &amp;quot;lblPort&amp;quot;&lt;br /&gt;
        Me.lblPort.Size = New System.Drawing.Size(113, 24)&lt;br /&gt;
        Me.lblPort.TabIndex = 3&lt;br /&gt;
        Me.lblPort.Text = &amp;quot;Port&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;txtPort&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.txtPort.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.txtPort.Location = New System.Drawing.Point(164, 31)&lt;br /&gt;
        Me.txtPort.Name = &amp;quot;txtPort&amp;quot;&lt;br /&gt;
        Me.txtPort.Size = New System.Drawing.Size(133, 26)&lt;br /&gt;
        Me.txtPort.TabIndex = 4&lt;br /&gt;
        Me.txtPort.Text = &amp;quot;&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;btnClose&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.btnClose.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.btnClose.Location = New System.Drawing.Point(471, 27)&lt;br /&gt;
        Me.btnClose.Name = &amp;quot;btnClose&amp;quot;&lt;br /&gt;
        Me.btnClose.Size = New System.Drawing.Size(102, 32)&lt;br /&gt;
        Me.btnClose.TabIndex = 5&lt;br /&gt;
        Me.btnClose.Text = &amp;quot;Stop Connection&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;txtContent&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.txtContent.Location = New System.Drawing.Point(164, 120)&lt;br /&gt;
        Me.txtContent.Multiline = True&lt;br /&gt;
        Me.txtContent.Name = &amp;quot;txtContent&amp;quot;&lt;br /&gt;
        Me.txtContent.Size = New System.Drawing.Size(389, 88)&lt;br /&gt;
        Me.txtContent.TabIndex = 6&lt;br /&gt;
        Me.txtContent.Text = &amp;quot;&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;Label1&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.Label1.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.Label1.Location = New System.Drawing.Point(61, 120)&lt;br /&gt;
        Me.Label1.Name = &amp;quot;Label1&amp;quot;&lt;br /&gt;
        Me.Label1.Size = New System.Drawing.Size(93, 24)&lt;br /&gt;
        Me.Label1.TabIndex = 7&lt;br /&gt;
        Me.Label1.Text = &amp;quot;Data&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;btnWrite&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.btnWrite.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.btnWrite.Location = New System.Drawing.Point(573, 120)&lt;br /&gt;
        Me.btnWrite.Name = &amp;quot;btnWrite&amp;quot;&lt;br /&gt;
        Me.btnWrite.Size = New System.Drawing.Size(123, 32)&lt;br /&gt;
        Me.btnWrite.TabIndex = 8&lt;br /&gt;
        Me.btnWrite.Text = &amp;quot;Write&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;Form1&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)&lt;br /&gt;
        Me.ClientSize = New System.Drawing.Size(716, 261)&lt;br /&gt;
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnWrite, Me.Label1, Me.txtContent, Me.btnClose, Me.txtPort, Me.lblPort, Me.lblConnection, Me.lblMessage, Me.btnListener})&lt;br /&gt;
        Me.Name = &amp;quot;Form1&amp;quot;&lt;br /&gt;
        Me.Text = &amp;quot;Form1&amp;quot;&lt;br /&gt;
        Me.ResumeLayout(False)&lt;br /&gt;
    End Sub&lt;br /&gt;
&lt;br /&gt;
    Dim intPort As Integer&lt;br /&gt;
    Dim myTcpListener As TcpListener&lt;br /&gt;
    Dim myNetworkStream As NetworkStream&lt;br /&gt;
    Private Sub btnListener_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListener.Click&lt;br /&gt;
        Dim myThread As New Thread(New ThreadStart(AddressOf StartListen))&lt;br /&gt;
        myThread.Start()&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private Sub StartListen()&lt;br /&gt;
        intPort = Integer.Parse(txtPort.Text)&lt;br /&gt;
        myTcpListener = New TcpListener(intPort)&lt;br /&gt;
        Dim blnConection As Boolean = False&lt;br /&gt;
        Try&lt;br /&gt;
            myTcpListener.Start()&lt;br /&gt;
            lblMessage.Text = &amp;quot;Waiting...&amp;quot;&lt;br /&gt;
            Dim mySocket As Socket = myTcpListener.AcceptSocket()&lt;br /&gt;
&lt;br /&gt;
            Do&lt;br /&gt;
                If mySocket.Connected = True Then&lt;br /&gt;
                    lblMessage.Text = &amp;quot;Port: &amp;quot; + txtPort.Text + &amp;quot;Connected&amp;quot;&lt;br /&gt;
                    myNetworkStream = New NetworkStream(mySocket)&lt;br /&gt;
                    Dim strContent As String&lt;br /&gt;
                    Dim lngByte As Long = myNetworkStream.ReadByte()&lt;br /&gt;
                    Dim myByte(lngByte) As Byte&lt;br /&gt;
                    myNetworkStream.Read(myByte, 0, lngByte)&lt;br /&gt;
                    strContent = Encoding.ASCII.GetString(myByte, 0, lngByte)&lt;br /&gt;
                    txtContent.Text = strContent&lt;br /&gt;
                End If&lt;br /&gt;
            Loop&lt;br /&gt;
        Catch ex As SocketException&lt;br /&gt;
            MessageBox.Show _&lt;br /&gt;
            (ex.Message, &amp;quot;Connection Error&amp;quot;, MessageBoxButtons.OK, MessageBoxIcon.Warning)&lt;br /&gt;
        End Try&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click&lt;br /&gt;
        myTcpListener.Stop()&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click&lt;br /&gt;
       &lt;br /&gt;
        Dim strTest As String = txtContent.Text&lt;br /&gt;
        Dim myBytes() As Byte = Encoding.ASCII.GetBytes(strTest)&lt;br /&gt;
        lblMessage.Text = (&amp;quot;Message&amp;quot;)&lt;br /&gt;
        myNetworkStream.Write(myBytes, 0, myBytes.Length)&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load&lt;br /&gt;
    End Sub&lt;br /&gt;
End Class&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using Async Socket Server==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;vbnet&amp;quot;&amp;gt;Imports System.Net.Sockets&lt;br /&gt;
Imports System.Net&lt;br /&gt;
Imports System.Threading&lt;br /&gt;
Imports System.Text&lt;br /&gt;
Imports System.Windows.Forms&lt;br /&gt;
public class UsingAsyncSocketServer&lt;br /&gt;
   public Shared Sub Main&lt;br /&gt;
        Application.Run(New Form1)&lt;br /&gt;
   End Sub&lt;br /&gt;
End class&lt;br /&gt;
Public Class Form1&lt;br /&gt;
    Inherits System.Windows.Forms.Form&lt;br /&gt;
    Public Sub New()&lt;br /&gt;
        MyBase.New()&lt;br /&gt;
        InitializeComponent()&lt;br /&gt;
    End Sub&lt;br /&gt;
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)&lt;br /&gt;
        If disposing Then&lt;br /&gt;
            If Not (components Is Nothing) Then&lt;br /&gt;
                components.Dispose()&lt;br /&gt;
            End If&lt;br /&gt;
        End If&lt;br /&gt;
        MyBase.Dispose(disposing)&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private components As System.ruponentModel.IContainer&lt;br /&gt;
    Friend WithEvents btnListener As System.Windows.Forms.Button&lt;br /&gt;
    Friend WithEvents lblConnection As System.Windows.Forms.Label&lt;br /&gt;
    Friend WithEvents lblPort As System.Windows.Forms.Label&lt;br /&gt;
    Friend WithEvents txtPort As System.Windows.Forms.TextBox&lt;br /&gt;
    Friend WithEvents btnClose As System.Windows.Forms.Button&lt;br /&gt;
    Friend WithEvents btnReceive As System.Windows.Forms.Button&lt;br /&gt;
    Friend WithEvents txtMessage As System.Windows.Forms.TextBox&lt;br /&gt;
    Friend WithEvents Label1 As System.Windows.Forms.Label&lt;br /&gt;
    Friend WithEvents btnSend As System.Windows.Forms.Button&lt;br /&gt;
    Friend WithEvents txtAccept As System.Windows.Forms.TextBox&lt;br /&gt;
    &amp;lt;System.Diagnostics.DebuggerStepThrough()&amp;gt; Private Sub InitializeComponent()&lt;br /&gt;
        Me.btnListener = New System.Windows.Forms.Button()&lt;br /&gt;
        Me.lblConnection = New System.Windows.Forms.Label()&lt;br /&gt;
        Me.lblPort = New System.Windows.Forms.Label()&lt;br /&gt;
        Me.txtPort = New System.Windows.Forms.TextBox()&lt;br /&gt;
        Me.btnClose = New System.Windows.Forms.Button()&lt;br /&gt;
        Me.btnReceive = New System.Windows.Forms.Button()&lt;br /&gt;
        Me.txtMessage = New System.Windows.Forms.TextBox()&lt;br /&gt;
        Me.txtAccept = New System.Windows.Forms.TextBox()&lt;br /&gt;
        Me.Label1 = New System.Windows.Forms.Label()&lt;br /&gt;
        Me.btnSend = New System.Windows.Forms.Button()&lt;br /&gt;
        Me.SuspendLayout()&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;btnListener&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.btnListener.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.btnListener.Location = New System.Drawing.Point(338, 24)&lt;br /&gt;
        Me.btnListener.Name = &amp;quot;btnListener&amp;quot;&lt;br /&gt;
        Me.btnListener.Size = New System.Drawing.Size(113, 32)&lt;br /&gt;
        Me.btnListener.TabIndex = 0&lt;br /&gt;
        Me.btnListener.Text = &amp;quot;Start&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;lblConnection&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.lblConnection.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.lblConnection.Location = New System.Drawing.Point(41, 72)&lt;br /&gt;
        Me.lblConnection.Name = &amp;quot;lblConnection&amp;quot;&lt;br /&gt;
        Me.lblConnection.Size = New System.Drawing.Size(92, 24)&lt;br /&gt;
        Me.lblConnection.TabIndex = 2&lt;br /&gt;
        Me.lblConnection.Text = &amp;quot;Info&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;lblPort&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.lblPort.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.lblPort.Location = New System.Drawing.Point(20, 32)&lt;br /&gt;
        Me.lblPort.Name = &amp;quot;lblPort&amp;quot;&lt;br /&gt;
        Me.lblPort.Size = New System.Drawing.Size(113, 24)&lt;br /&gt;
        Me.lblPort.TabIndex = 3&lt;br /&gt;
        Me.lblPort.Text = &amp;quot;Port&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;txtPort&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.txtPort.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.txtPort.Location = New System.Drawing.Point(143, 24)&lt;br /&gt;
        Me.txtPort.Name = &amp;quot;txtPort&amp;quot;&lt;br /&gt;
        Me.txtPort.Size = New System.Drawing.Size(133, 26)&lt;br /&gt;
        Me.txtPort.TabIndex = 4&lt;br /&gt;
        Me.txtPort.Text = &amp;quot;36000&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;btnClose&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.btnClose.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.btnClose.Location = New System.Drawing.Point(461, 24)&lt;br /&gt;
        Me.btnClose.Name = &amp;quot;btnClose&amp;quot;&lt;br /&gt;
        Me.btnClose.Size = New System.Drawing.Size(102, 32)&lt;br /&gt;
        Me.btnClose.TabIndex = 5&lt;br /&gt;
        Me.btnClose.Text = &amp;quot;Stop&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;btnReceive&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.btnReceive.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.btnReceive.Location = New System.Drawing.Point(276, 248)&lt;br /&gt;
        Me.btnReceive.Name = &amp;quot;btnReceive&amp;quot;&lt;br /&gt;
        Me.btnReceive.Size = New System.Drawing.Size(175, 32)&lt;br /&gt;
        Me.btnReceive.TabIndex = 6&lt;br /&gt;
        Me.btnReceive.Text = &amp;quot;Receive&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;txtMessage&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.txtMessage.Location = New System.Drawing.Point(143, 72)&lt;br /&gt;
        Me.txtMessage.Multiline = True&lt;br /&gt;
        Me.txtMessage.Name = &amp;quot;txtMessage&amp;quot;&lt;br /&gt;
        Me.txtMessage.ScrollBars = System.Windows.Forms.ScrollBars.Vertical&lt;br /&gt;
        Me.txtMessage.Size = New System.Drawing.Size(430, 88)&lt;br /&gt;
        Me.txtMessage.TabIndex = 7&lt;br /&gt;
        Me.txtMessage.Text = &amp;quot;&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;txtAccept&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.txtAccept.Location = New System.Drawing.Point(143, 168)&lt;br /&gt;
        Me.txtAccept.Multiline = True&lt;br /&gt;
        Me.txtAccept.Name = &amp;quot;txtAccept&amp;quot;&lt;br /&gt;
        Me.txtAccept.ScrollBars = System.Windows.Forms.ScrollBars.Vertical&lt;br /&gt;
        Me.txtAccept.Size = New System.Drawing.Size(430, 64)&lt;br /&gt;
        Me.txtAccept.TabIndex = 9&lt;br /&gt;
        Me.txtAccept.Text = &amp;quot;&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;Label1&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.Label1.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.Label1.Location = New System.Drawing.Point(10, 168)&lt;br /&gt;
        Me.Label1.Name = &amp;quot;Label1&amp;quot;&lt;br /&gt;
        Me.Label1.Size = New System.Drawing.Size(144, 24)&lt;br /&gt;
        Me.Label1.TabIndex = 8&lt;br /&gt;
        Me.Label1.Text = &amp;quot;Data&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;btnSend&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.btnSend.Font = New System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))&lt;br /&gt;
        Me.btnSend.Location = New System.Drawing.Point(461, 248)&lt;br /&gt;
        Me.btnSend.Name = &amp;quot;btnSend&amp;quot;&lt;br /&gt;
        Me.btnSend.Size = New System.Drawing.Size(112, 32)&lt;br /&gt;
        Me.btnSend.TabIndex = 10&lt;br /&gt;
        Me.btnSend.Text = &amp;quot;Data sent back&amp;quot;&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        &amp;quot;Form1&lt;br /&gt;
        &amp;quot;&lt;br /&gt;
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)&lt;br /&gt;
        Me.ClientSize = New System.Drawing.Size(665, 309)&lt;br /&gt;
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnSend, Me.txtAccept, Me.Label1, Me.txtMessage, Me.btnReceive, Me.btnClose, Me.txtPort, Me.lblPort, Me.lblConnection, Me.btnListener})&lt;br /&gt;
        Me.Name = &amp;quot;Form1&amp;quot;&lt;br /&gt;
        Me.Text = &amp;quot;Form1&amp;quot;&lt;br /&gt;
        Me.ResumeLayout(False)&lt;br /&gt;
    End Sub&lt;br /&gt;
    Dim strMessage&lt;br /&gt;
    Dim myListener As Socket&lt;br /&gt;
    Dim bteAccept(65536) As Byte&lt;br /&gt;
    Dim bteSend(65536) As Byte&lt;br /&gt;
    Dim EndSocket As Socket&lt;br /&gt;
    Private Sub btnListener_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListener.Click&lt;br /&gt;
        Dim myThread As New Thread(New ThreadStart(AddressOf StartListen))&lt;br /&gt;
        myThread.Start()&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private Sub btnReceive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReceive.Click&lt;br /&gt;
        Dim myThread As New Thread(New ThreadStart(AddressOf ReceiveStart))&lt;br /&gt;
        myThread.Start()&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click&lt;br /&gt;
        Dim myThread As New Thread(New ThreadStart(AddressOf SendStart))&lt;br /&gt;
        myThread.Start()&lt;br /&gt;
    End Sub&lt;br /&gt;
&lt;br /&gt;
    Private Sub StartListen()&lt;br /&gt;
        Dim intPort As Integer&lt;br /&gt;
        Dim bidEndPoint As IPEndPoint&lt;br /&gt;
        intPort = Integer.Parse(txtPort.Text)&lt;br /&gt;
        bidEndPoint = New IPEndPoint(IPAddress.Parse(&amp;quot;10.2.3.127&amp;quot;), intPort)&lt;br /&gt;
        myListener = New Socket _&lt;br /&gt;
                     (AddressFamily.InterNetwork, _&lt;br /&gt;
                     SocketType.Stream, _&lt;br /&gt;
                     ProtocolType.Tcp)&lt;br /&gt;
        Try&lt;br /&gt;
            &amp;quot;  myListener.Bind(bidEndPoint)&lt;br /&gt;
            Dim myAsyncCallBack As New AsyncCallback(AddressOf AcceptEnd)&lt;br /&gt;
            myListener.Listen(intPort)&lt;br /&gt;
            myListener.BeginAccept(myAsyncCallBack, myListener)&lt;br /&gt;
            txtMessage.Text += vbCrLf + &amp;quot;Waiting&amp;quot;&lt;br /&gt;
            strMessage += &amp;quot;//Head...&amp;quot; + vbCrLf&lt;br /&gt;
            strMessage += &amp;quot;//Server Send Message ...&amp;quot; + vbCrLf&lt;br /&gt;
            strMessage += &amp;quot;--------------------------------&amp;quot; + vbCrLf&lt;br /&gt;
&lt;br /&gt;
        Catch ex As SocketException&lt;br /&gt;
            Console.WriteLine(ex.Message)&lt;br /&gt;
        End Try&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private Sub AcceptEnd(ByVal pIAsyncResult As IAsyncResult)&lt;br /&gt;
        EndSocket = myListener.EndAccept(pIAsyncResult)&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private Sub ReceiveStart()&lt;br /&gt;
        Dim myAsyncCallBack As New AsyncCallback(AddressOf ReceiveData)&lt;br /&gt;
        EndSocket.BeginReceive _&lt;br /&gt;
          (bteAccept, 0, 65536, 0, _&lt;br /&gt;
          myAsyncCallBack, EndSocket)&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private Sub ReceiveData(ByVal pIAsyncResult As IAsyncResult)&lt;br /&gt;
        Dim intByte As Integer&lt;br /&gt;
        intByte = EndSocket.EndReceive(pIAsyncResult)&lt;br /&gt;
        If intByte &amp;gt; 0 Then&lt;br /&gt;
            strMessage += Encoding.ASCII.GetString(bteAccept)&lt;br /&gt;
            txtAccept.Text = strMessage&lt;br /&gt;
        End If&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private Sub SendStart()&lt;br /&gt;
        Dim myAsyncCallBack As New AsyncCallback(AddressOf SendData)&lt;br /&gt;
        bteSend = Encoding.ASCII.GetBytes(strMessage)&lt;br /&gt;
        EndSocket.BeginSend _&lt;br /&gt;
          (bteSend, 0, bteSend.Length, _&lt;br /&gt;
          SocketFlags.DontRoute, myAsyncCallBack, EndSocket)&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private Sub SendData(ByVal pIAsyncResult As IAsyncResult)&lt;br /&gt;
        Dim intSend As Integer&lt;br /&gt;
        intSend = EndSocket.EndSend(pIAsyncResult)&lt;br /&gt;
        txtMessage.Text += vbCrLf + &amp;quot;Data sent &amp;quot; + intSend.ToString + &amp;quot;bytes&amp;quot;&lt;br /&gt;
    End Sub&lt;br /&gt;
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click&lt;br /&gt;
        myListener.Close()&lt;br /&gt;
    End Sub&lt;br /&gt;
&lt;br /&gt;
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load&lt;br /&gt;
    End Sub&lt;br /&gt;
End Class&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>