Ive been wanting to create a simple Server-Client programs and Ive searched the net alot, but all the coding online are very complex for a newbie. So Atheist helped me code a simple TCP communication program
The original topic is http://www.vbforums.com/showthread.php?t=502795
Attached is the Server code and Client code
have fun
This code is exactly what I was after thank you.
One small thing though, the client app sends a message saying /DISCONNECT before it disconnects, which fires an event on the server. Is there anyway to have the server fire an event when a client leaves, without needing the client to send a message?
what if you want to stop listener? I mean if the user wants to change username or port?
This is where you start to listen from clients:
listener = New TcpListener(IPAddress.Any, txtPort.Text)
listener.Start() 'Start listening.
listenThread = New Thread(AddressOf DoListen)
listenThread.IsBackground = True
listenThread.Start()
And here's the DoListen
Private Sub DoListen()
Dim incomingClient As System.Net.Sockets.TcpClient
Do
incomingClient = listener.AcceptTcpClient
Dim connClient As New ConnectedClient(incomingClient, Me)
AddHandler connClient.dataReceived, AddressOf Me.MessageReceived
clients.Add(connClient) 'Adds the connected client to the list of connected clients.
Me.MessageReceived
Loop
End Sub
How do you stop listener? I tried doing this but I always get an error:
1. When I want to send every message from every client to all connected clients (multiusers chat) I try with this:
Code:
For Each cc As ConnectedClient In clients
cc.SendMessage(receivedString)
Next
but problem is because when is connected 10-12 peoples and writing to much sometime happend that two, or more messages going in one LINE.
For example, if I send "test", my friend 1 send "test2" its showing like this:
stefanACM: testfriend1: test2
How to solve that ???
2. What is easiest way to transfer CLIENT LIST to every client ?
I'm a newbie to VB 2010 Express and I just wanted to say a huge thank you to both Atheist and perito for your threads on Basic TCP Communication.
I had a small project where I wanted to download trace data from an RF spectrum analyzer and place it into a .CSV file for analysis. Your comments, tutorials and examples have proved invaluable to me. My little project has been a success!
how can i turn this code into a messenger? as in multiple ppl sending message to each other? do i need to send the message to the server thn to the client?
for example
I'm attempting to run this in VS 2012 Express....but the server is showing 58 errors and the client is showing 50 errors. Is this just not compatible with VS 2012 or should I keep trying?