Tcp client server

xtheonex

New member
Joined
Nov 19, 2008
Messages
1
Programming Experience
Beginner
Ok, so im new to VB and i cant make sense of any tutorials or sample code.

Im a PHP programmer normally, so i understand the basics of loops and conditionals and stuff like that.

But im trying to basically create 2 apps.

First app is the server app that i want to be a form and it simply display how many users are connected.

And the second app, i want to be a form also, but simply have 2 buttons on it that connect and disconnect it from the server. And a label or textbox... etc that says how many apps are connected to the server app.

All the samples/tutorials ive seen have loads of extra stuff, or use a console app for the server part... etc.

I want the simplest code possible to do what i mentioned above so i can try and understand how it works.

Sorry if y'all get asked this often, i have looked at the forum for answers but cant seem to find anything that i can make sense of.

Thanks in advance,
Dave
 
vokay here is a verry simple code. The server keeps waiting to accept the incoming requests from the clients. Once a client connects it just displays the client IP on the console.

////////////////Server Side Code//////////////////


Sub Main()
ListenForClients()
End Sub

Private oListner As System.Net.Sockets.TcpListener
Private thStart As Threading.Thread

Private Sub ListenForClients()
oListner = New System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, 9999)
oListner.Start()
thStart = New Threading.Thread(AddressOf AcceptClients)
thStart.Start()
End Sub

Private Sub AcceptClients()
Dim oSocket As System.Net.Sockets.Socket
While True
oSocket = oListner.AcceptSocket()
Console.WriteLine(oSocket.RemoteEndPoint)
End While
End Sub


/////////////////////////Client Side Code/////////////////////


Sub Main()
Dim oTcpClient As New System.Net.Sockets.TcpClient
oTcpClient.Connect("192.168.1.2", 9999)
End Sub


I think this will be helpfull. You can use the oTcpClient.GetStream() method to get the network stream. Using the stram object you can transfer the data.

On the server side use the socket object to receive the data.

Krsh
 
Back
Top