Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Sending variables over a network vb.net

Options
  • 02-05-2006 4:06pm
    #1
    Registered Users Posts: 4,946 ✭✭✭


    Hey guys, i've been working on a program for quite some time now that required me to send 1 simple string over a network. I've been messing about with UDP And TCP and Im seriously having no joy what so ever. Both ends, send and recieve are annoying me, and im on the verge of throwing in the towel.

    What i have on the send button

    Dim pRet As Integer

    Try
    GLOIP = IPAddress.Parse(txtIP.Text)
    GLOINTPORT = txtPort.Text
    udpClient.Connect(GLOIP, GLOINTPORT)
    bytCommand = Encoding.ASCII.GetBytes(txtMessage.Text)
    pRet = udpClient.Send(bytCommand, bytCommand.Length)
    Console.WriteLine("No of bytes send " & pRet)
    txtInfo.Text = "INFORMATION" & vbCrLf & "No of bytes send " & pRet
    Console.WriteLine(Encoding.ASCII.GetString(bytCommand))
    txtInfo.Text = txtInfo.Text + vbCrLf + "The messege send is """
    txtInfo.Text = txtInfo.Text & Encoding.ASCII.GetChars(bytCommand) & """"
    Dim BitDet As BitArray
    BitDet = New BitArray(bytCommand)
    txtInfo.Text = txtInfo.Text + vbCrLf
    Dim tempStr As String
    Dim tempStr2 As String
    Dim i As Integer
    i = 0
    Dim j As Integer
    j = 0
    Dim line As Integer
    line = 0
    txtInfo.Text = txtInfo.Text + line.ToString & ") "
    For j = 0 To BitDet.Length - 1
    If BitDet(j) = True Then
    Console.Write("1 ")
    tempStr2 = tempStr
    tempStr = " 1" + tempStr2
    Else
    Console.Write("0 ")
    tempStr2 = tempStr
    tempStr = " 0" + tempStr2
    End If
    i += 1
    If i = 8 And j <= (BitDet.Length - 1) Then
    line += 1
    i = 0
    txtInfo.Text = txtInfo.Text + tempStr
    tempStr = ""
    tempStr2 = ""
    txtInfo.Text = txtInfo.Text + vbCrLf
    If j <> (BitDet.Length - 1) Then
    txtInfo.Text = txtInfo.Text + line.ToString & ") "
    Console.WriteLine()
    End If
    End If
    Next




    Catch ex As Exception
    Console.WriteLine(ex.Message)
    txtInfo.Text = txtInfo.Text & vbCrLf & ex.Message
    End Try

    I got that code from a site, which i think has to be overly complecated.


    Has anyone got experience with this in .net?
    Would anyone be able to help me by throwing up some code?
    Is there anyway i can dumb that down to 10 lines of code like the good old days of VB 6 and winsock?
    Could jesus microwave a bureto so hot that he himself could not eat it?

    Too many questions...

    Cheers

    reddy


Comments

  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    this is C# code, but the idea should be the same in VB.NET.... This should work, i did something like this before (except slightly more complicated) but i'm working from memory now.
    // Make an internet TCP socket.
    Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    
    //The byte array holding the data. Populate this as per usual
    byte[] myData = new byte[100];
    
    // connect to port 80 on whatever address.
    socket.Connect("134.341.12.52", 8080); 
    if (socket.Connected)
    {
          socket.Send(myData);
    }
    

    That should send the data no problem so long as the remote host is set up correctly to recieve. What errors are you getting?


Advertisement