Click to See Complete Forum and Search --> : Combining VB and Mobile VB?
weisi
Jan 26th, 2005, 10:46 AM
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
Shaggy Hiker
Jan 26th, 2005, 08:25 PM
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.
weisi
Jan 26th, 2005, 10:38 PM
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!
Shaggy Hiker
Jan 28th, 2005, 06:15 PM
Public Class ConnectionPDA
Private quitFlag As Boolean
Private conOut As System.Net.Sockets.TcpClient
Private netStream As System.Net.Sockets.NetworkStream
Private linOpt As System.Net.Sockets.LingerOption
Private myTimer As System.Windows.Forms.Timer
Private bTimedOut As Boolean
#Region "Constructors and Destructors"
Public Sub New()
'Create the timer
myTimer = New System.Windows.Forms.Timer
'Need to tell it where to send time tick messages.
AddHandler myTimer.Tick, AddressOf TimerEventProcessor
'This is set so that we can know the status if nothing is received.
bTimedOut = False
' Sets the timer interval to 5 seconds.
myTimer.Interval = 5000
myTimer.Enabled = False
quitFlag = True
linOpt = New System.Net.Sockets.LingerOption(True, 5)
End Sub
Public Sub Dispose()
'This may not be essential, but give it a go.
If Not netStream Is Nothing Then
netStream.Close()
End If
If Not conOut Is Nothing Then
conOut.Close()
End If
myTimer.Dispose()
End Sub
#End Region
#Region "Public Functions"
'If this is true, then the time event fired. Basically, this means that if
'RetrieveData() returned an empty string, it was because of timing out.
Public Function TimedOut() As Boolean
TimedOut = Me.TimedOut
End Function
Public Function BeginCommunicate() As Boolean
Dim st1 As String
Dim flag As Boolean
Dim rVal As Integer
Try
conOut = New System.Net.Sockets.TcpClient("PPP_PEER", 2000)
conOut.LingerState = linOpt
netStream = conOut.GetStream
BeginCommunicate = True
Catch ex As Exception
BeginCommunicate = False
End Try
End Function
Public Function RetrieveData() As String
Dim recBuff(2048) As Byte
Dim recCount As Integer
Dim st1 As String
Dim hasRead As Boolean
hasRead = False
'Get ready to read.
quitFlag = True
myTimer.Enabled = True
Try
Do While quitFlag
If netStream.DataAvailable Then
recCount = netStream.Read(recBuff, 0, 2048)
End If
If recCount > 0 Then
hasRead = True
'Turn it into a string.
st1 &= System.Text.Encoding.Default.GetString(recBuff, 0, recCount)
'Clear out the buffer.
recBuff.Clear(recBuff, 0, 2048)
recCount = 0
Else
'If hasRead is set, then something has been received, but the last loop
'returned nothing. Therefore, we are done reading.
If hasRead Then
'This is simply cleared to stop the loop.
quitFlag = False
End If
'DoEvents, but only if nothing is coming in!
Application.DoEvents()
End If
Loop
Catch ex As Exception
'Nothing can be done here, but that's ok.
MsgBox(ex.Message)
End Try
'Get out.
Me.bTimedOut = False
RetrieveData = st1
End Function
Public Function SendData(ByVal st1 As String) As Boolean
Dim sendBuff(2048) As Byte
Try
sendBuff = System.Text.Encoding.Default.GetBytes(st1.ToCharArray())
netStream.Write(sendBuff, 0, sendBuff.GetLength(0))
SendData = True
Catch ex As Exception
SendData = False
End Try
End Function
#End Region
#Region "Private Functions"
Private Sub TimerEventProcessor(ByVal myObject As Object, ByVal myEventArgs As EventArgs)
myTimer.Enabled = False
quitFlag = False
Me.bTimedOut = True
End Sub
#End Region
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.
weisi
Jan 29th, 2005, 12:57 AM
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
Shaggy Hiker
Jan 31st, 2005, 12:40 PM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.