Maverick Posted July 24, 2004 Posted July 24, 2004 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 Quote
Administrators PlausiblyDamp Posted July 24, 2004 Administrators Posted July 24, 2004 (edited) 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: Edited May 4, 2007 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Maverick Posted July 26, 2004 Author Posted July 26, 2004 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 Quote
Maverick Posted July 29, 2004 Author Posted July 29, 2004 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 Quote
Administrators PlausiblyDamp Posted July 29, 2004 Administrators Posted July 29, 2004 (edited) 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. Edited May 4, 2007 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Maverick Posted July 29, 2004 Author Posted July 29, 2004 (edited) there ya go i am using BeginAccept and EndAccept 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 Edited July 30, 2004 by Maverick Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.