I'm sorry if this in the wrong section.
I'm trying to learn network programming. I have found a pretty easy example on internet, here: Socket Programming using Visual Basic.Net - .Net Articles & Samples
He describes how to make a simple chat program. The problem is thatit only works on one computer. Somehow i want to make the server use the internal ip or a
Hamachi adress, but i don't know how. Here's the code:
The Client:
Imports System.IO
Imports System.Net.Sockets
And the server:
Any ideas?
I'm trying to learn network programming. I have found a pretty easy example on internet, here: Socket Programming using Visual Basic.Net - .Net Articles & Samples
He describes how to make a simple chat program. The problem is thatit only works on one computer. Somehow i want to make the server use the internal ip or a
Hamachi adress, but i don't know how. Here's the code:
The Client:
Imports System.IO
Imports System.Net.Sockets
VB.NET:
Module Module1
Sub Main()
Try
Console.WriteLine("Connecting to 8585 Local Host")
Dim serverListener As New TcpClient("localhost", 8585)
Dim readStream As Stream = serverListener.GetStream
serverListener.SendBufferSize = 256
Console.WriteLine("Input Lines:")
Dim str As String = Console.ReadLine()
While True
Dim sendBuff As Byte() = System.Text.Encoding.ASCII.GetBytes(str)
readStream.Write(sendBuff, 0, sendBuff.Length)
If str.StartsWith(".") Then
GoTo Done
End If
str = Console.ReadLine()
End While
Done: Console.WriteLine("Done")
Catch exp As Exception
Console.WriteLine("Exception: " + exp.ToString())
End Try
End Sub
End Module
And the server:
VB.NET:
Imports System.IO
Imports System.Net.Sockets
Module Module1
Sub Main()
Console.WriteLine("")
Dim clientListener As New TcpListener(8585)
clientListener.Start()
Console.WriteLine("")
Dim mySocket As Socket = clientListener.AcceptSocket()
Console.WriteLine("")
Dim recieveBuff(225) As Byte
mySocket.Receive(recieveBuff, recieveBuff.Length, SocketFlags.None)
Dim str As String = System.Text.Encoding.ASCII.GetString(recieveBuff, 0, recieveBuff.Length).Trim(Microsoft.VisualBasic.ChrW(0))
While Not str.StartsWith(".")
Console.WriteLine(str)
mySocket.Receive(recieveBuff, recieveBuff.Length, SocketFlags.None)
str = System.Text.Encoding.ASCII.GetString(recieveBuff, 0, recieveBuff.Length).Trim(Microsoft.VisualBasic.ChrW(0))
End While
Console.WriteLine("")
clientListener.Stop()
End Sub
End Module
Any ideas?