This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MulticastClient{ | |
public final static int MULTICAST_PORT = 50001; | |
public final static String MULTICAST_GROUP = "127.0.0.1"; | |
public static void main(String[] args){ | |
try { | |
MulticastSocket clientSocket = new MulticastSocket(MULTICAST_PORT); | |
clientSocket.joinGroup(InetAddress.getByName(MULTICAST_GROUP)); | |
byte[] dataBuffer = new byte[]; | |
DatagramPacket inputPacket = new DatagramPacket(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MulticastServer { | |
public final static int MULTICAST_PORT = 50001; | |
public final static String MULTICAST_GROUP = "127.0.0.1"; | |
public static void main(String[] args){ | |
try { | |
DatagramSocket serverSocket = new DatagramSocket(); | |
byte[] dataBuffer = new byte[1024]; | |
DatagramPacket outputPacket = new DatagramPacket( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react'; | |
import { generatePath } from "react-router"; | |
const GeneratePathExample = () => { | |
const [isPosts, setIsPosts] = useState(false); | |
let url = generatePath("/user/:id/:entity(posts|comments)", { | |
id: 1, | |
entity: isPosts ? "posts" : "comments" | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import ReactDOMServer from "react-dom/server"; | |
import { StaticRouter } from "react-router"; | |
const express = require('express') | |
const app = express() | |
const port = 3000 | |
app.get('/', (req, res) => { | |
// This context object contains the results of the render | |
const context = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { shallow, mount } from 'enzyme'; | |
import Routes from './Routes'; | |
import Home from './Home'; | |
import { MemoryRouter } from 'react-router' | |
describe('routes using memory router', () => { | |
it('should show Home component for / route', () => { | |
const component = mount( | |
<MemoryRouter initialEntries="{['/']}"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState} from 'react'; | |
import {Prompt} from 'react-router-dom'; | |
const PromptExample = () => { | |
const [isCompleted,setCompleted] = useState(false); | |
return ( | |
<> | |
<Prompt | |
when={!isCompleted} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.net.Socket; | |
public class SocketClient { | |
public static void main(String[] args){ | |
try { | |
Socket clientSocket = new Socket ("localhost",50001); | |
InputStream is = clientSocket.getInputStream(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.DataOutputStream; | |
import java.io.IOException; | |
import java.net.ServerSocket; | |
import java.net.Socket; | |
public class SocketServer { | |
public static final int SERVER_PORT = 50001; | |
public static void main (String[] args){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import { Text } from 'react-native'; | |
import { useIsFocused } from '@react-navigation/native'; | |
function Profile() { | |
// This hook returns `true` if the screen is focused, `false` otherwise | |
const isFocused = useIsFocused(); | |
return <Text>{isFocused ? 'focused' : 'unfocused'}</Text>; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useFocusEffect } from '@react-navigation/native'; | |
function Profile() { | |
useFocusEffect( | |
React.useCallback(() => { | |
// Do something when the screen is focused | |
return () => { | |
// Do something when the screen is unfocused | |
// Useful for cleanup functions |