seeking advice

Maverick

Newcomer
Joined
Oct 13, 2003
Messages
13
Location
London
Hi
i am new to .net and i am planning to start working on a Client/Server application.
now i have heard of 2 classes that can be used as server for listening
TCPListener and Socket class(async), which one is better and easier? and is there a good tutorial for creating a server/client apps in vb.net?

thanks
 
TCPListner and TCPClient give a very easy to use implementation for a networked application. They provide a Stream interface so they can be used just like File I/O under .Net.
Using the socket class involves more work but gives you finer control over how things work and also provides asynchronous capabilities - which could give much better performance in production code.
IIRC there is a simple client/server chat program installed as sample when you do a VS install - just can't rememberer where it is though :confused:
 
Last edited:
yeah i found it thanks... and its a pretty good example..
one question tho: is there a limitation for the tcplistenter like the maximum number of connections it can take? and why is using the socket class better than tcpListener?

thanks again
 
hi
i got my own server working in vb.net using Socket class not TcpClient...
not we all know that Socket class uses async mode to handle everything..

how can i use OOP to be able to save each socket i receieve a connection in a collection and be able to loop through them when i want to broadcast?

thanks again
 
How are you opening the incoming connections on the server? If you are just using the .Accept method on a socket then you could always just add the returned socket to a collection.

If you post the server's code for handling incoming connections then it will be a bit easier to see how you are currently doing things.
 
Last edited:
there ya go
i am using BeginAccept and EndAccept
Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Visible = True
        NewThread = New Threading.Thread(AddressOf Listen)
        NewThread.Start()
    End Sub
    Private Sub Listen()
        Dim EP As New IPEndPoint(IPAddress.Any, 3600)
        Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        Try
            TextBox1.Text += "Started Listening" & vbCrLf
            Socket.Bind(EP)
            Socket.Listen(1000)
            While True
                AllDone.Reset()
                Socket.BeginAccept(New AsyncCallback(AddressOf NewConnection), Socket)
                AllDone.WaitOne()
            End While

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
its derived from MSDN socket class documentation
i wanna use this code to be able to create a class with it and the rest of the events so that i will be able to store all these instances in a collection or a hashtable.

thanks for ur help
Maverick
 
Last edited:
Back
Top