Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client and Server application problem

Status
Not open for further replies.

leangross

IS-IT--Management
Jul 3, 2002
84
PH
hi im creating a client and server application that communicates with each other. Im just wondering why i cant read the data send from the client to my server (listener)application?

HEre is my code

Client:
Code:
 Dim s As Socket
 Dim SendData As String = "Sending this from client application."

        Try
            s = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
            s.Connect(Sethost("127.0.0.1", 9999))
            Dim msg As Byte() = Encoding.ASCII.GetBytes(SendData)
            Console.WriteLine(Encoding.ASCII.GetString(msgbytes))
            s.Send(msg, msg.Length, SocketFlags.None)

        Catch ex As SocketException
            Console.WriteLine(("Source : " + ex.Source))
            Console.WriteLine(("Message : " + ex.Message))

        End Try

Server code:
Code:
 Dim serverlistener As TcpListener
        Dim s As Socket
        Dim Str() As Byte
        Dim tclient As TcpClient
        Try
            Dim port As Int32 = 9999
            Dim localAddr As IPAddress = IPAddress.Parse("127.0.0.1")

            ServerListener = New TcpListener(localAddr, port)
            ServerListener.Start()

            While True
                s = serverlistener.AcceptSocket
                Console.WriteLine("socket connection accepted")

                s.Receive(Str, s.Available, SocketFlags.None)
                Console.WriteLine(Encoding.ASCII.GetString(sStr))
                Console.ReadLine()
            End While


        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Console.ReadLine()
        End Try
 
I take it that you are running both client and server on the same machine.

It could be that you av is blocking the high number port, try 81 which shouldn't already be used by your local machine.

If that doesn't work, get back to me and I'll have another think about it.
 
hi, the port 9999 is unused. Any idea why?

Thanks
 
Well, your anti-virus program may block high port numbers because some viruses use these ports for sending data back to the hackers server. You can enable the port manually, but I thought that if you use port 81 to test it out before opening your computers ports. Just to let you know, port 9999 is known as a spyware port, so it may be blocked on other machines as well.

Everything else in your code looks fine, except I haven't used Sethost before.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top