TcpClient TcpListener

DrizztTheDrow

New member
Joined
Jan 27, 2007
Messages
3
Programming Experience
1-3
I programmed alot in VB, but never anything in VB.net i need help with a simple message displaying thing.i just want, one person types something into a textbox, and antoher person can click refresh and a msg goes up (same as the one in host). i really suck right now, so all i have is.. and i dont even know if it is right.

Host/person who types in message
Imports System.Threading

Imports System.Net

Imports System.Net.Sockets

Imports System.IO

PublicClass Form1
Dim client As System.Net.Sockets.TcpListener
PrivateSub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim msg AsString

msg = TextBox1.Text

EndSub
EndClass


Client/receiving message
Imports System.Threading
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
PublicClass Form1
Dim host As System.Net.Sockets.TcpClient
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim host AsNew System.Net.Sockets.TcpClient("192.168.1.152", "5555")
host.GetStream()


EndSub
PrivateSub Form1_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
EndSub
EndClass
 
Client TcpClient must connect to server. Server TcpListener must be listening and accept the call, which returns a TcpClient used for communication. With established connection they both use the Reads and Writes methods of NetworkStream. Get aquainted with the documentation for these three classes. Search up some beginner examples, here is one for starters: http://www.eggheadcafe.com/articles/20020323.asp
 
Ya, but that doesn't matter for the tcp code. Whether user input/output in console window or a textbox should be the same. But try out that code with a console just for the laughs, all you need to do is copy/paste. Learn about the objects used that you don't already know. The very basic listen/connect/accept/read/write is displayed in that example. Everybody have to start somewhere, even the first three letters in the alphabet "ABC".
 
Back
Top