Hi,

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

Firstly, We want to transfer a string data from the client to server, to do this we
follow the logic given below.

Sub SendData()
Dim objTCPClient As New TcpClient()
Dim objStream As Stream
Dim bytMessage(1000) As Byte
Dim strMessage as string = "Sample Message"

objTCPClient = New TcpClient()
objTCPClient.Connect(strContactIPAddr, strContactPortNumber)

objStream = objTCPClient.GetStream()
bytMessage = System.Text.Encoding.ASCII.GetBytes(strMessage)

objStream.Write(bytMessage, 0, Len(strMessage))

objTCPClient.Close()
objTCPClient = Nothing
End Sub

when we execute the above piece of code, it sends the data to the server application
which has been listening for request at a particular ip address and port. When we verified
the string data received from the socket's input stream, we get "Sample Message as the
received text, we would like to know why the ending " (double quotes) is missing here.

Secondly, from the server application, we have a sub routine called Listener,
which is invoked periodically using Timer object from System.Threading namespace. Inside
this subroutine, we used ListenerObject.AcceptSocket() to receive the data sent from
various systems. Here, we are trying to load windows form instances dynamically based upon
the client which sent the data. This subroutine receives data from various client systems

properly, but the 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

process. The code snippet used for the above process is given 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 those windows.

When we close the main window, all the windows opened through Listenr sub routine get
closed.

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

Regards,
Deva.