Hi,

We are developing an utility using Socket programming, we face a problem here, we would
like to take your inputs to resolve these errors.

We have written a server application which listens for data from multiple clients. The same
application is capable of sending messages to other clients, especially to the client
from whom it received the message. To take care of this requirement, we placed the
TCPListener in a subroutine and executed this subroutine using timer object from
System.Threading namespace. This particular subroutine is invoked periodiacally say
once in four seconds or once in five seconds throug this timer object.

From this subroutine, we used TCPListener object's AcceptSocket method to receive data
from other clients. Now, after receiving a message from a client, we want to load a form
dynamically by displaying the message we received.

This subroutine receives data from various client systems properly, but the windows form which we are opening from this procedure comes to the foreground, but we could not set focus to this form and use it in the normal way. It is constantly blocked by some system process. This
form is hangling and we could not do operation using this.

We have loaded another form before we listen for requests from clients, we are able
to use this form in the normal way. It tells us that the application does not hang-up,
just the form we loaded through listener procedure is blocked. We have provided the
code snippet below for your reference.

In a module file, we have the public variables as mentioned below.

Public objTcpListener As TcpListener
Public objTimer As System.Threading.Timer

From a form load event, we execute the code given below.

objTcpListener = New TcpListener(strPortNumber)
objTcpListener.Start()

objTimer = New Timer(New TimerCallback(AddressOf Listener), Nothing, 0, 1000)


Sub Listener()
Dim objSocket As Socket
Dim bytMessage(1000) As Byte

objSocket = objTcpListener.AcceptSocket()
objSocket.Receive(bytMessage)
strMessage = Encoding.ASCII.GetString(bytMessage)

Dim obj_frm_Message as new frmMessage
obj_frm_Message.lblMessage = strMessage
obj_frm_Message.Show()
obj_frm_Message.Focus()

objSocket.Close()
Application.DoEvents()
End Sub

As we mentioned earlier, we could execute the logic given above successfully, it pops up
the new window with the message sent by the tcp client application, but we could not set
focus to the window which is poped up, it is constantly blocked by some system process and
we could not do any operation with this window.

Can you give us your inputs to resolve the above mentioned issues, we look forward
for your replies, thank you.

Regards,
Deva.