Results 1 to 6 of 6

Thread: Combining VB and Mobile VB?

  1. #1
    Hyperactive Member
    Join Date
    Aug 04
    Posts
    344

    Combining VB and Mobile VB?

    May I know how am I going to combine a VB application and Mobile VB application? I have a chat application between a client and a server using Mobile VB and a file transfer application between a server and client written in VB. Can I just create a form in the chat application and dump the whole file transfer coding into the form? Or is there any way which I can do? Thank you!


    Weisi

  2. #2
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,570

    Re: Combining VB and Mobile VB?

    Just because of the cost (in time) of loading forms on a mobile, you probably do not want to make a separate form for the file transfer. If there is a user interface component on the file transfer part, the easiest thing to do would be to put all the components into a panel, then move the panel out of view during form loading, and move it back into view when you need it. This is far faster than switching between forms.

    Will the file transfer code from a desktop work on a mobile: Maybe. Kind of depends on how you do the communication. A server generally is set to listen for connection requests, which you can't do on a mobile, which means the mobile has to be the client. Simple sockets using TCPClient would work, and would be easy to implement, but that may be how the file transfer is set up now.

    One thing that I find unclear in your post is what you want to end up with in the end. What is the program supposed to do? You seem to be trying to merge some functionality between two different apps, but it isn't clear what the final answer would be.
    My usual boring signature: Nothing

  3. #3
    Hyperactive Member
    Join Date
    Aug 04
    Posts
    344

    Re: Combining VB and Mobile VB?

    we want to combine chat and transfer application, using MobileVB to do client part, after that upload client part to POCKET PC. but errors exist when upload thde client part we have combined, the error is #1036 whic is "errors (1 items) must be fixed to deploy this project"

    The final result is that the client is able to send message to the server and vice versa. The server is also able to send file to the client. Therefore the client is able to recieve file from the server. any suggestion to us?
    thanks!
    Last edited by weisi; Jan 27th, 2005 at 03:33 AM.

  4. #4
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,570

    Re: Combining VB and Mobile VB?

    VB Code:
    1. Public Class ConnectionPDA
    2.     Private quitFlag As Boolean
    3.     Private conOut As System.Net.Sockets.TcpClient
    4.     Private netStream As System.Net.Sockets.NetworkStream
    5.     Private linOpt As System.Net.Sockets.LingerOption
    6.     Private myTimer As System.Windows.Forms.Timer
    7.     Private bTimedOut As Boolean
    8.  
    9.  
    10.  
    11. #Region "Constructors and Destructors"
    12.     Public Sub New()
    13.  
    14.         'Create the timer
    15.         myTimer = New System.Windows.Forms.Timer
    16.  
    17.         'Need to tell it where to send time tick messages.
    18.         AddHandler myTimer.Tick, AddressOf TimerEventProcessor
    19.  
    20.         'This is set so that we can know the status if nothing is received.
    21.         bTimedOut = False
    22.  
    23.         ' Sets the timer interval to 5 seconds.
    24.         myTimer.Interval = 5000
    25.         myTimer.Enabled = False
    26.         quitFlag = True
    27.         linOpt = New System.Net.Sockets.LingerOption(True, 5)
    28.     End Sub
    29.  
    30.     Public Sub Dispose()
    31.         'This may not be essential, but give it a go.
    32.         If Not netStream Is Nothing Then
    33.             netStream.Close()
    34.         End If
    35.         If Not conOut Is Nothing Then
    36.             conOut.Close()
    37.         End If
    38.         myTimer.Dispose()
    39.     End Sub
    40. #End Region
    41.  
    42. #Region "Public Functions"
    43.  
    44.     'If this is true, then the time event fired. Basically, this means that if
    45.     'RetrieveData() returned an empty string, it was because of timing out.
    46.     Public Function TimedOut() As Boolean
    47.         TimedOut = Me.TimedOut
    48.     End Function
    49.  
    50.     Public Function BeginCommunicate() As Boolean
    51.         Dim st1 As String
    52.         Dim flag As Boolean
    53.         Dim rVal As Integer
    54.  
    55.         Try
    56.             conOut = New System.Net.Sockets.TcpClient("PPP_PEER", 2000)
    57.             conOut.LingerState = linOpt
    58.             netStream = conOut.GetStream
    59.             BeginCommunicate = True
    60.         Catch ex As Exception
    61.             BeginCommunicate = False
    62.         End Try
    63.  
    64.     End Function
    65.  
    66.     Public Function RetrieveData() As String
    67.         Dim recBuff(2048) As Byte
    68.         Dim recCount As Integer
    69.         Dim st1 As String
    70.         Dim hasRead As Boolean
    71.  
    72.         hasRead = False
    73.         'Get ready to read.
    74.         quitFlag = True
    75.         myTimer.Enabled = True
    76.         Try
    77.             Do While quitFlag
    78.                 If netStream.DataAvailable Then
    79.                     recCount = netStream.Read(recBuff, 0, 2048)
    80.                 End If
    81.                 If recCount > 0 Then
    82.                     hasRead = True
    83.                     'Turn it into a string.
    84.                     st1 &= System.Text.Encoding.Default.GetString(recBuff, 0, recCount)
    85.                     'Clear out the buffer.
    86.                     recBuff.Clear(recBuff, 0, 2048)
    87.                     recCount = 0
    88.                 Else
    89.                     'If hasRead is set, then something has been received, but the last loop
    90.                     'returned nothing. Therefore, we are done reading.
    91.                     If hasRead Then
    92.                         'This is simply cleared to stop the loop.
    93.                         quitFlag = False
    94.                     End If
    95.                     'DoEvents, but only if nothing is coming in!
    96.                     Application.DoEvents()
    97.                 End If
    98.             Loop
    99.  
    100.         Catch ex As Exception
    101.             'Nothing can be done here, but that's ok.
    102.             MsgBox(ex.Message)
    103.         End Try
    104.         'Get out.
    105.         Me.bTimedOut = False
    106.         RetrieveData = st1
    107.     End Function
    108.  
    109.     Public Function SendData(ByVal st1 As String) As Boolean
    110.         Dim sendBuff(2048) As Byte
    111.  
    112.         Try
    113.             sendBuff = System.Text.Encoding.Default.GetBytes(st1.ToCharArray())
    114.             netStream.Write(sendBuff, 0, sendBuff.GetLength(0))
    115.             SendData = True
    116.         Catch ex As Exception
    117.             SendData = False
    118.         End Try
    119.     End Function
    120.  
    121.  
    122. #End Region
    123.  
    124. #Region "Private Functions"
    125.  
    126.     Private Sub TimerEventProcessor(ByVal myObject As Object, ByVal myEventArgs As EventArgs)
    127.         myTimer.Enabled = False
    128.         quitFlag = False
    129.         Me.bTimedOut = True
    130.     End Sub
    131.  
    132. #End Region
    133. End Class

    Here's a class I wrote to get data from a desktop into a PDA. It appears to work fairly well, though there are probably a few improvements that could be made. There is a timer in there that is set for a 5 second delay. The purpose for the timer is to allow the server side to do some processing before looking for returned info.

    There is another side of this, but I wrote it single threaded when it should be multi threaded, and I need to change that.

    This may be of some interest.
    My usual boring signature: Nothing

  5. #5
    Hyperactive Member
    Join Date
    Aug 04
    Posts
    344

    Re: Combining VB and Mobile VB?

    Thanks for the reply! Does the code you written allow the server (PC) to send file to the client (PDA). Can it be written in Mobile VB?


    Weisi

  6. #6
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,570

    Re: Combining VB and Mobile VB?

    What I posted is written in the .NET Compact Framework, so it should run on a mobile system (Windows CE, not Palm OS).

    In theory, the ReceiveData method should be able to take in a chunk of data of any size (up to the limit of a string, which is huge). However, I am not sure whether or not I have tested it to see how it works with strings larger than the buffer size of 2048. This is part of a work in progress, and what I am passing is tables in XML strings. The code has worked fine for that, but I am not sure how large the largest string I have passed was.

    If the file is text, it should work. If the file can be packed into an XML string, then it should be fine. As for a straight file transfer, some modifications will probably be needed.

    This line (found in RetrieveData()):

    st1 &= System.Text.Encoding.Default.GetString(recBuff, 0, recCount)

    turns the buffered bytes into a string. In the case of a file, unless it is a text file, that is almost certainly not what you want to do. Instead, you will need to repackage the bytes in a different fashion, but that is not something I have dealt with.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •