[go: up one dir, main page]

0% found this document useful (0 votes)
89 views1 page

Network Programming in Java Exercises

The document outlines 3 exercises for writing network programming client/server systems in Java: 1. A TCP system where a client sends two numbers to a server which returns the sum. 2. A UDP system where a client sends a number from 1-10 and the server returns the corresponding string from an array. 3. A system where multiple clients can send messages to a server, which rebroadcasts each message to all clients in a multicast group.

Uploaded by

JacquesVerges
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views1 page

Network Programming in Java Exercises

The document outlines 3 exercises for writing network programming client/server systems in Java: 1. A TCP system where a client sends two numbers to a server which returns the sum. 2. A UDP system where a client sends a number from 1-10 and the server returns the corresponding string from an array. 3. A system where multiple clients can send messages to a server, which rebroadcasts each message to all clients in a multicast group.

Uploaded by

JacquesVerges
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Network

 Programming  in  Java  


Exercises  
1.  Write  a  TCP  client/server  system  in  which  the  client  program  sends  two  
numbers  to  a  server  program  which  returns  the  sum  of  the  two  numbers.  
 
2.  Write  a  UDP  client/server  system  in  which  the  client  program  sends  a  number  
between  1  and  10  and  the  server  program  returns  the  corresponding  element  in  
an  array  of  strings.  
 
You  might  find  the  following  static  methods  useful:  
 
       public  static  byte[]  intToByteArray(int  value)  {  
               byte[]  b  =  new  byte[4];  
               for  (int  i  =  0;  i  <  4;  i++)  {  
                       int  offset  =  (b.length  -­‐  1  -­‐  i)  *  8;  
                       b[i]  =  (byte)  ((value  >>>  offset)  &  0xFF);  
               }  
               return  b;  
       }  
 
       public  static  int  byteArrayToInt(byte[]  b,  int  offset)  {  
               int  value  =  0;  
               for  (int  i  =  0;  i  <  4;  i++)  {  
                       int  shift  =  (4  -­‐  1  -­‐  i)  *  8;  
                       value  +=  (b[i  +  offset]  &  0x000000FF)  <<  shift;  
               }  
               return  value;  
       }  
 
3.  Write  a  client/server  system  in  which  each  of  any  number  of  copies  of  a  client  
program  can  send  a  message  to  a  server  program  which  re-­‐broadcasts  the  
message  to  all  the  clients  in  a  multicast  group.  

You might also like