Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Code Samples & Tips Share your recent discoveries and ideas with other users.

Interprocess communication with the Network library

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-19-2008, 10:37 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default Interprocess communication with the Network library

One way to communicate between two processes is to open a network socket on each process and use the local host IP (127.0.0.1) to send and receive messages.
One application will play the server role and the other will be the client.
IPC1 code (server):
Code:
Sub App_Start
    Form1.Show
    TimeFormat(
"hh:mm:ss")
    client.New1
    server.New1(
55555)
    server.Start
    tmrWaitForOtherApp.Enabled = 
true
End Sub

Sub Button1_Click
    bin.WriteString(
"Time: " & Time(Now) & " Hello from IPC1")
End Sub

Sub tmrWaitForOtherApp_Tick
    
If server.Pending Then
        client.Value = server.Accept
        bin.New1(client.GetStream,
false)
        tmrWaitForOtherApp.Enabled = 
false
        tmrWaitForData.Enabled = 
true
        Button1.Enabled = 
true
    
End If
End Sub

Sub tmrWaitForData_Tick
    
If client.DataAvailable Then
        textBox1.Text = bin.ReadString
    
End If
End Sub
The server uses two timers. The first one - tmrWaitForOtherApp waits for the other application to connect.
The second timer - tmrWaitForData checks if there is data waiting to be read.

IPC2 code (client side):
Code:
Sub App_Start
    Form1.Show
    TimeFormat(
"hh:mm:ss")
    client.New1
    
Do Until ConnectToServer = true
        
If Msgbox("Please first run IPC1.exe." & crlf _  
            & 
"Try again?","",cMsgboxYesNo) = cNo Then AppClose
    
Loop
End Sub

Sub ConnectToServer
    ErrorLabel(NoServer)
    client.Connect(
"127.0.0.1",55555)
    bin.New1(client.GetStream,
false)
    tmrWaitForData.Enabled = 
true
    Button1.Enabled = 
true
    
Return true
NoServer:
    
Return false
End Sub
Sub Button1_Click
    bin.WriteString(
"Time: " & Time(Now) & " Hello from IPC2")
End Sub


Sub tmrWaitForData_Tick
    
If client.DataAvailable Then
        textBox1.Text = bin.ReadString
    
End If
End Sub
The client side tries to connect with the server. If connection failed (most probably because IPC1 is not running) then it shows a message and tries to connect again.
The client also uses a timer to check for available data.
The source code and compiled executables are attached.
Attached Files
File Type: zip IPC.zip (31.7 KB, 123 views)
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Serial communication - problems with reading token Questions (Windows Mobile) 11 02-19-2009 01:51 PM
WLAN communication WolfgangGruia Questions (Windows Mobile) 24 08-02-2008 07:02 PM
Complex Network Library Example aerohost Questions (Windows Mobile) 5 06-29-2008 12:25 PM
Network Heinz Questions (Windows Mobile) 1 02-24-2008 10:30 AM
Network "library" agraham Additional Libraries 2 11-11-2007 09:32 AM


All times are GMT. The time now is 10:03 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0