Multiple socket

N

N.Naeem

Hello all

I am a newbie to VB.NET and i need a solution to the following problem

I have an application which listens to a port for incoming connections from
a client via a socket.

Upon a connection of a client i would like the application to call another
FORM which also has a socket, and i would like to transfer the first socket
information to the 2nd socket, hence allowing the client now to talk
directly to the 2nd socket,
and hence free up the initial socket to start listening again.

I have looked into some examples nad have a basic understanding of how
sockets work.

TIA
 
D

David Browne

N.Naeem said:
Hello all

I am a newbie to VB.NET and i need a solution to the following problem

I have an application which listens to a port for incoming connections from
a client via a socket.

Upon a connection of a client i would like the application to call another
FORM which also has a socket, and i would like to transfer the first socket
information to the 2nd socket, hence allowing the client now to talk
directly to the 2nd socket,
and hence free up the initial socket to start listening again.

I have looked into some examples nad have a basic understanding of how
sockets work.

With only a basic understanding of sockets, you might want to work with the
TCP/IP helper classed TCPListener, TCPClient, and streams. Here's an
example of a simple telnet server.

David
Sub main()

Dim sl As New Net.Sockets.TcpListener(System.Net.IPAddress.Any, 23)
sl.Start()

Do
Dim tc As TcpClient = sl.AcceptTcpClient()
Threading.ThreadPool.QueueUserWorkItem(AddressOf converse, tc)
Loop
End Sub

Sub converse(ByVal o As Object)
Dim tc As TcpClient = DirectCast(o, TcpClient)
Dim s As IO.Stream = tc.GetStream
Dim tr As New IO.StreamReader(s, System.Text.Encoding.ASCII)
Dim tw As New IO.StreamWriter(s, System.Text.Encoding.ASCII)
tw.AutoFlush = True
Do
Dim l As String = tr.ReadLine()
If l = "" Then
Exit Do
End If
Console.WriteLine(l)
tw.WriteLine("Received " & l)
Loop

tr.Close()
tw.Close()
s.Close()

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top