Hazardous_Byte 0 Newbie Poster

Hey everyone! It has been a very long time since I posted, but I have a new question for you guys.
So, I made a sort of "remote-desktop" program that allows me to move the mouse from another computer. However, the mouse will move to where I want it but it will either be really choppy or just loose the connection. Here is how it works, so you guys can poke and prod at it.
Server-Receiving

While True
            Dim clientListener As New TcpListener(8585)
            Dim clientListener2 As New TcpListener(8000)
            Dim clientListener3 As New TcpListener(5000)


            clientListener.Start()
            clientListener2.Start()
            clientListener3.Start()


            Dim mySocket As Socket = clientListener.AcceptSocket()
            Dim mySocket2 As Socket = clientListener2.AcceptSocket()
            Dim mySocket3 As Socket = clientListener3.AcceptSocket()


            mySocket.NoDelay = True
            mySocket2.NoDelay = True
            mySocket3.NoDelay = True
            Dim recieveBuff(1000) As Byte
            Dim recieveBuff2(1000) As Byte
            Dim recieveBuff3(1000) As Byte


            mySocket.Receive(recieveBuff, recieveBuff.Length, SocketFlags.None)
            mySocket2.Receive(recieveBuff2, recieveBuff2.Length, SocketFlags.None)
            mySocket3.Receive(recieveBuff3, recieveBuff3.Length, SocketFlags.None)

            Dim str As String = System.Text.Encoding.ASCII.GetString(recieveBuff, 0, recieveBuff.Length).Trim(Microsoft.VisualBasic.ChrW(0))
            Dim str2 As String = System.Text.Encoding.ASCII.GetString(recieveBuff2, 0, recieveBuff2.Length).Trim(Microsoft.VisualBasic.ChrW(0))
            Dim str3 As String = System.Text.Encoding.ASCII.GetString(recieveBuff3, 0, recieveBuff3.Length).Trim(Microsoft.VisualBasic.ChrW(0))
            On Error Resume Next






            mySocket.Receive(recieveBuff)
            mySocket2.Receive(recieveBuff2)
            mySocket3.Receive(recieveBuff3)


          
            Cursor.Position = New Point(CInt(str), CInt(str2))




            If CDbl(str3) = 1 Then

                mouse_event(2, 100, 100, 0, 0)
                str3 = ("0")
            Else
                mouse_event(4, 100, 100, 0, 0)
                str3 = ("0")
            End If

            clientListener.Stop()
            clientListener2.Stop()
            clientListener3.Stop()
            mySocket.Close()
            mySocket2.Close()
            mySocket3.Close()

As for the client, the sending is done by a timer. here is the code within the timer.tick:

str = CStr(Windows.Forms.Cursor.Position.X)
        str2 = CStr(Windows.Forms.Cursor.Position.Y)
        str3 = (" ")


        Try
            TextBox2.Text = ("Connected.")


            If String.IsNullOrEmpty(TextBox3.Text) Then
                Form2.Close()

                Threading.Thread.Sleep(1000)
                Me.Close()

            End If

            Dim serverListenerX As New TcpClient(TextBox3.Text, 8585)
            Dim serverListenerY As New TcpClient(TextBox3.Text, 8000)
            serverListenerX.NoDelay = True
            serverListenerY.NoDelay = True
            Dim readStream As Stream = serverListenerX.GetStream
            Dim readStream2 As Stream = serverListenerY.GetStream
            Dim sendBuff As Byte() = System.Text.Encoding.ASCII.GetBytes(str)
            Dim sendBuff2 As Byte() = System.Text.Encoding.ASCII.GetBytes(str2)
            Dim sendBuff3 As Byte() = System.Text.Encoding.ASCII.GetBytes(str3)
            Form2.Show()
            readStream.Write(sendBuff, 0, sendBuff.Length)
            readStream2.Write(sendBuff2, 0, sendBuff2.Length)
            readStream.Close()
            readStream2.Close()





        Catch
            TextBox2.Text = ("Reconnecting...")

            mousetimer.Stop()

            mousetimer.Start()
        End Try

If anyone out there has experience with sockets, please explain what I am doing wrong!


Thanks again, Hazardous_Byte.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.