Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Administrators
Posted (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 by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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

Posted

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

  • Administrators
Posted (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 by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (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 by Maverick

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...