Tutorial by Examples: commun

Server: Start, and wait for incoming connections //Open a listening "ServerSocket" on port 1234. ServerSocket serverSocket = new ServerSocket(1234); while (true) { // Wait for a client connection. // Once a client connected, we get a "Socket" object // that c...
Channels can be used to send data from one thread to another. Below is an example of a simple producer-consumer system, where the main thread produces the values 0, 1, ..., 9, and the spawned thread prints them: use std::thread; use std::sync::mpsc::channel; fn main() { // Create a channel...
This code example creates a TCP client, sends "Hello World" over the socket connection, and then writes the server response to the console before closing the connection. // Declare Variables string host = "stackoverflow.com"; int port = 9999; int timeout = 5000; // Create ...
There are multiple threads in your code and you need to safely communicate between them. You can use a Queue from the queue library. from queue import Queue from threading import Thread # create a data producer def producer(output_queue): while True: data = data_computation() ...
As Handlers are used to send Messages and Runnables to a Thread's message queue it's easy to implement event based communication between multiple Threads. Every Thread that has a Looper is able to receive and process messages. A HandlerThread is a Thread that implements such a Looper, for example th...
Taken from jQuery.ajax API web site: $.ajax({ method: "POST", url: "some.php", data: { name: "John", location: "Boston" }, success: function(msg) { alert("Data Saved: " + msg); }, error: ...
Matlab supports synchronous and asynchronous communication with a serial port. It is important to chose the right communication mode. The choice will depend on: how the instrument you are communicating with behave. what other functions your main program (or GUI) will have to do aside from managi...
Client.java import java.io.*; import java.net.*; public class Client{ public static void main(String [] args) throws IOException{ DatagramSocket clientSocket = new DatagramSocket(); InetAddress address = InetAddress.getByName(args[0]); String ex = "He...
Example demonstrates component composition and one-way message passing from parent to children. 0.18.0 Component composition relies on Message tagging with Html.App.map 0.18.0 In 0.18.0 HTML.App was collapsed into HTML Component composition relies on Message tagging with Html.map Example ...
Session Types are a way to tell the compiler about the protocol you want to use to communicate between threads - not protocol as in HTTP or FTP, but the pattern of information flow between threads. This is useful since the compiler will now stop you from accidentally breaking your protocol and causi...
It is very easy to pass information between threads using the MVar a type and its accompanying functions in Control.Concurrent: newEmptyMVar :: IO (MVar a) -- creates a new MVar a newMVar :: a -> IO (MVar a) -- creates a new MVar with the given value takeMVar :: MVar a -> IO a -- retrieve...
WebSocket provides a duplex/bidirectional communication protocol over a single TCP connection. the client opens a connection to a server that is listening for a WebSocket request a client connects to a server using a URI. A server may listen to requests from multiple clients. Server Endpoint...
Since workers run in a separate thread from the one that created them, communication needs to happen via postMessage. Note: Because of the different export prefixes, some browsers have webkitPostMessage instead of postMessage. You should override postMessage to make sure workers "work" (n...
To setup a WebRTC-based communication system, you need three main components: A WebRTC signaling server To establish a WebRTC connections, peers need to contact a signaling server, which then provides the address information the peers require to set up a peer-to-peer connection. Signaling serv...
You can communicate two activities so that Activity A can be notified of an event happening in Activity B. Activity A final String eventName = "your.package.goes.here.EVENT"; @Override protected void onCreate(Bundle savedInstanceState) { registerEventReceiver(); super.onCre...
Android Activity package com.example.myapp; import android.os.Bundle; import android.app.Activity; import android.webkit.WebView; public class WebViewActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceSta...
Basic Example package com.example.myapp; import android.os.Bundle; import android.app.Activity; import android.webkit.WebView; public class WebViewActivity extends Activity { private Webview webView; @Override protected void onCreate(Bundle savedInstanceState) { ...
When using a WebView to display your own custom webpage and this webpage contains Javascript, it might be necessary to establish a two-way communication between the Java program and the Javascript in the web page. This example shows how to setup such a communication. The webpage shall display an i...
Main process source code index.js: const {app, BrowserWindow, ipcMain} = require('electron') let win = null app.on('ready', () => { win = new BrowserWindow() win.loadURL(`file://${__dirname}/index.html`) win.webContents.openDevTools() win.on('closed', () => { win = null ...
Interprocess communication allows programmers to communicate between different processes. For example let us consider we need to write an PHP application that can run bash commands and print the output. We will be using proc_open , which will execute the command and return a resource that we can com...

Page 1 of 2