Vb.Net => Java
Vb.Net => Java
Vb.Net => Java
Vb.Net => Java
Vb.Net => Java
Vb.Net => Java Vb.Net => Java Vb.Net => Java Vb.Net => Java Vb.Net => Java Vb.Net => Java Vb.Net => Java Vb.Net => Java
Vb.Net => Java Vb.Net => Java
Vb.Net => Java
Go Back  Xtreme Visual Basic Talk > > > Vb.Net => Java


Reply
 
Thread Tools Display Modes
  #1  
Old 01-17-2011, 07:25 AM
Guest0496 Guest0496 is offline
Newcomer
 
Join Date: Apr 2010
Posts: 15
Default Vb.Net => Java


I'm attempting to write a vb.net client that needs to connect to a java server.
As it stands, I am able to connect to the java server via putty, and it works perfectly (using raw mode)
The vb.net client can connect and receive data, but it doesn't seem to be sending it correctly, because the java server never responds.

I didn't write the java server, but the source is avalible.
after a long amount of research, i found out that java useds BigEndianUnicode when sending packets, which is how I managed to get my client to receive any data in the first place..

heres the source:

Code:
Imports System.Net.Sockets
Imports System.Text

Module Module1



    Sub Main()

start:

        Console.WriteLine("Connecting to server..")

        Dim clientsocket As New System.Net.Sockets.TcpClient
        clientsocket.Connect("127.0.0.1", 6790)

        Do Until clientsocket.Connected = True
            System.Threading.Thread.Sleep(1)
        Loop

        Console.WriteLine("Connected to server.")
        Console.WriteLine("Setting up receive thread.")

        Dim Inc As New Receive
        Inc.client = clientsocket

        Dim RecThread As New System.Threading.Thread(AddressOf Inc.rec)
        RecThread.Start()


        Do Until True = False
            System.Threading.Thread.Sleep(1)

            If Inc.data.Count > 0 Then
                Dim data As String = Inc.data.Item(1)
                Inc.data.Remove(1)

                Console.WriteLine(data)

                If InStr(data, "Welcome") Then
                    Console.WriteLine("Sending Login..")
                    Dim Out As [Byte]() = System.Text.Encoding.BigEndianUnicode.GetBytes("pass password".ToCharArray)
                    Dim serverstream As NetworkStream = Inc.client.GetStream
                    serverstream.Write(Out, 0, Out.Length)
                    serverstream.Flush()
                End If


            End If

            If Inc.client.Connected = False Then
                Console.WriteLine("Connection Failed! Trying Again..")
                RecThread.Abort()
                GoTo start
            End If


        Loop


    End Sub

End Module
Code:
Imports System.Net.Sockets
Imports System.Text

Public Class Receive

    Public client As TcpClient
    Public data As New Collection

    Public Sub rec()

        Do Until True = False
            System.Threading.Thread.Sleep(1)
            Dim all() As Byte = New Byte() {}

            If client.GetStream.DataAvailable Then
                Do While client.GetStream.DataAvailable
                    Dim bytesFrom(10024) As Byte
                    Dim serverstream As NetworkStream = client.GetStream()
                    Dim size = serverstream.Read(bytesFrom, 0, (CInt(client.ReceiveBufferSize)))

                    ReDim Preserve bytesFrom(size - 1)
                    ReDim Preserve all(all.length + size - 1)
                    Array.Copy(bytesFrom, 0, all, all.Length - size, bytesFrom.Length)

                    System.Threading.Thread.Sleep(500)
                Loop

                Dim dataFrom As String = System.Text.Encoding.BigEndianUnicode.GetString(all)
                data.Add(dataFrom)

            End If


        Loop


    End Sub

End Class
I can link to the java source if required, any help is appreciated.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Vb.Net => Java
Vb.Net => Java
Vb.Net => Java Vb.Net => Java
Vb.Net => Java
Vb.Net => Java
Vb.Net => Java Vb.Net => Java Vb.Net => Java Vb.Net => Java Vb.Net => Java Vb.Net => Java Vb.Net => Java
Vb.Net => Java
Vb.Net => Java
 
Vb.Net => Java
Vb.Net => Java
 
-->