what direction should I take for sending data over Internet

qex

Regular
Joined
Apr 2, 2003
Messages
78
I have a program that I want to be able to send data across the internet. I don't want a user front end though I want it done behind the scenes. Essentially I just want to be able to upload a transaction file of sorts to some distant webserver. I don't know where to start though.

2nd part:
I've been playing with the msdn example with tcplistener I can send data between two apps using my local machine but if I try to put the app on another computer on my LAN I get a Socket Exception "No connection could be made because the target machine actively refused it"

Any help will be appreciated.

Thanks
 
If you just wish to transfer information to a remote system then you may want to investigate web-services as a possible means.
When you say put the app on another computer do you mean the client, server or both? If you are moving either the client or server make sure you are trying to connect to the server using either it's correct name or ip address.
 
I put the listener on another pc "B" that is listening on port 13000 supposedly. I have the other app running on a different pc "A" that I point to "B" at port 13000 using :

client = New TcpClient(server, port)
stream = client.GetStream() 'stream is network stream

where "server" is the IP of pc "B"

Its not getting to the stream = line because the above line is where it throws the socket exception I described in the above post

PC A and B are right here in front of me and I have the IP for both but I can't get it to connect

any suggestions? I'm running win2k are there are permission issues or security issues with using port 13000.
 
Back to the big picture using an XML webservice how easy/hard is it to secure the data that is being transmitted the data is private in nature and would need to be encrypted in some way.
 
Yes, I can ping the server. I have a packet sniffer on the server end and I turned it on and I can see the requests coming from the client and I see ACK's going back but this happens whether my program is running or not. A connection is never made however. I tried using a different port in case there was something running on 13000, but I get the same ACKs...
 
Here is the listener code which runs on the pc I am trying to connect to
Code:
Sub ListenForRequests()

        Try

            ' Set the TcpListener on port 13000.
            Dim port As Int32 = 13000
            Dim localAddr As IPAddress = Dns.Resolve("localhost").AddressList(0)
            iplabel.Text = "Listening on IP: " & localAddr.ToString() & " Port: " & port
            Dim server As New System.Net.Sockets.TcpListener(localAddr, port)

            ' Start listening for client requests.
            server.Start()

            ' Buffer for reading data
            Dim bytes(1024) As [Byte]
            Dim data As [String] = Nothing

            ' Enter the listening loop.
            While Alive
                rtb.Text = rtb.Text & "Waiting for a connection... " & ControlChars.CrLf

                ' Perform a blocking call to accept requests.
                ' You could also user server.AcceptSocket() here.

                Dim client As TcpClient = server.AcceptTcpClient()

                rtb.Text = rtb.Text & "Connected!" & ControlChars.CrLf

                data = Nothing

                ' Get a stream object for reading and writing
                Dim stream As NetworkStream = client.GetStream()

                Dim i As Int32

                ' Loop to receive all the data sent by the client.
                i = stream.Read(bytes, 0, bytes.Length)
                While (i <> 0)
                    ' Translate data bytes to a ASCII string.
                    data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
                    rtb.Text = rtb.Text & "Received:" & data & ControlChars.CrLf

                    ' Process the data sent by the client.
                    data = data.ToUpper()


                    Dim msg As [Byte]() = System.Text.Encoding.ASCII.GetBytes(data)

                    ' Send back a response.
                    stream.Write(msg, 0, msg.Length)
                    rtb.Text = rtb.Text & "Sent: " & data & ControlChars.CrLf

                    i = stream.Read(bytes, 0, bytes.Length)

                End While

                ' Shutdown and end connection
                client.Close()
            End While
        Catch e As SocketException
            MessageBox.Show("SocketException: " & e.Message)
        End Try


    End Sub
 
Here is the client code that connects to the listener its essentially code that I pulled from the MSDN. Let me know if you see anything.
Code:
Sub Connect(ByVal server As [String], ByVal port As [Int32])
        Try
            ' Create a TcpClient.
            ' Note, for this client to work you need to have a TcpServer 
            ' connected to the same address as specified by the server, port
            ' combination.
            client = New TcpClient(server, port)
            stream = client.GetStream()
        Catch e As ArgumentNullException
            MsgBox("ArgumentNullException: " & e.Message)
        Catch e As SocketException
            MessageBox.Show("SocketException: " & e.Message)
        End Try
 
Try changing
Visual Basic:
 Dim server As New System.Net.Sockets.TcpListener(localAddr, port)
'to
 Dim server As New System.Net.Sockets.TcpListener(IPAddress.Any, port)
you are currently only listening on the 127.0.0.1 address rather than your real network address.
 
thanks that worked... I was thinking that when you set the ip to the local host that it would look at anything on that NIC, but I guess not.
 
You were giving it a specific ip address to listen on - unfortunately the one you specified was 127.0.0.1!
Normally this would only be required on a server with multiple ip addresses or multiple physical adapters and you only wanted it to listen on 1. My code just listens on all local addresses.
 
Last edited:
Wicked, I made the same mistake, but I found this post and solved my problem, just the way I thought, that it was the local machine that should listen, but it wanted to know which machines it should listen for instead, :-)

Pt. Google rocks, cause it guided me to this page

Regards MrBonus
 
Back
Top