Or the homework of the experiment ~Total two files required, this is the client1#include 2#include 3#include 4#include 5#include string.h>6#include 7 8 #defineEchomax 2559 Ten intMainintargcChar*argv[]) { One intsock; A structsockaddr_in echoservaddr; - structsockaddr_in fromaddr; -Unsigned ShortEchoservport; theUnsignedintfromsize; - Char*Servip; - Char*echostring; - Charechobuffer[echomax+1]; + intechostringlen=0; - i
One. Service-side code:
Import java.io.*;
Import java.net.*;
public class Udpechoserver {
private static final int echomax = 255://Maximum size of Echo datagram public
Stati c void Main (string[] args) throws IOException {
int servport = 5500;//Server port
datagramsocket socket = new Da Tagramsocket (servport);
Datagrampacket packet = new Datagrampacket (new Byte[echomax
, serveraddress, 7);
Datagrampacket receivepacket = new Datagrampacket (new Byte[bytestosend.length), bytestosend.length);
Packets May is lost, so we have to keep trying int tries = 0;
Boolean receivedresponse = false;
do {socket.send (sendpacket);
try {socket.receive (receivepacket);
if (!receivepacket.getaddress (). Equals (serveraddress)) throw new IOException ("Receive from unknown Source");
Receivedresponse = true;
catch (IOException e) {tries++;
differences between UDP and TCP. One is that it does not need to establish a connection, and the other is that it retains the message boundary in each message sent and received.Server
Because UDP does not need to establish a connection, the process is as follows:
1. Construct an initramsocket instance and specify the local port.
2. Use the receive method of the initramsocket instance to receive the contents of the communication in the middle of DatagramPacket. DatagramPacket.
3. Use the send an
is as follows:1. Construct the Datagramsocket instance, specifying the local port.2. The Receive method of the Datagramsocket instance receives the content of the communication in the middle of the datagrampacket.datagrampacket.3. Receive and send Datagrampacket through the Datagramsocket send and receive methods.The typical interaction process code is as follows:1. Build the Datagramsocket instance, specifying the local port. Datagramsocket socket = new Datagramsocket (servport);//2. Build Dat
[*]}" One EchoMax is $max A EchoMin is $minView Code1 #!/bin/bash2 re= 'WC -L $1cut"" -F1 ' 3echo $reView CodeContinue and breakContinue and break can be added after a number n, indicating that the first n-level of the current round of the end of the cycle so that directly into the next round of judgment, the most inner layer of the loop is the 1th layerContinue 2 or Break 3Loop Control Shift CommandMove the parameter list to the left, the default mo
12,345.6812*345 #68
Iv. mathematical functions
Function
Function
ABS ()
Take absolute value
Floor ()
Rounding
Ceil ()
Returns an integer.
Round ()
Rounding
Min ()
Minimum value or the minimum value in the array
Max ()
Returns the maximum value or the maximum value in the array.
$=-123456.789;$ B=Array(1,2,3,4);EchoABS ($);Echo';EchoFloor ($);Echo';EchoCeil ($);Echo';EchoRound ($);
'
$f = $fruits;
while ($elem = each ($f)) {
echo$elem[' key '. '-'. $elem [' value ']. '
}
echo '
$arr 5=array (2, 8, 100, 33,-18);
Find the maximum minimum value
Echomax ($arr 5);
Contact Us
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.