Can someone help me tranfer this from a Console app to a WinForms app?
I'm still new to this and I want to build on top of this once I get
more acquainted with VB.net. I don't know if this may be helpful, but
I'm using Visual Studio 2008 (not express).
The Server Code I Found Online:
Imports System.Net.Sockets
Imports System.Text
Imports System.IO
Imports System.Net
Imports Microsoft.VisualBasic
Module Module1
Sub Main()
Dim port As Int32 = 500
Dim localAddr As IPAddress = IPAddress.Parse("192.168.0.5")
Dim serverSocket As New TcpListener(localAddr, port)
Dim requestCount As Integer
Dim clientSocket As TcpClient
serverSocket.Start()
msg("Server Started")
clientSocket = serverSocket.AcceptTcpClient()
msg("Accept connection from client")
requestCount = 0
While (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
("$"))
msg("Data from client - " + 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()
msg(serverResponse)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End While
clientSocket.Close()
serverSocket.Stop()
msg("exit")
Console.ReadLine()
End Sub
Sub msg(ByVal mesg As String)
mesg.Trim()
Console.WriteLine(" >> " + mesg)
End Sub
End Module
I would like a multiline textbox or either a rich textbox on the form
to receive the messages and each message to be on a new line.
If anyone can help me out here I would really be thankful!