UDP & TCP

Cancelled Posted Aug 6, 2006 Paid on delivery
Cancelled Paid on delivery

hi there

i have the following code , its using to open a chanel by TCP and UDP between server and client ,it must have input and output result like randome integer or any message, its must contain a GUI interface.

ex:if i wrote this sentence in the client"hello from client ", it must be sending to the server , to be sure its delivery to the server , the server must give me message like this "from server : hello from client ", it must doing using the TCP once and another time using UDP

it will be like of contain this code from Distributed Systems, Concepts and Design book , and its a homework

there is a code in the deliverables i hope its help you , and i am sorry for my bad language

## Deliverables

Figure 4.3

UDP client sends a message to the server and gets a reply

*import java.net.*;

* *import java.io.*;

**public class UDPClient{

** public static void main(String args[]){* *// args give message contents and server hostname* *DatagramSocket aSocket = null;* * try {* *aSocket = new DatagramSocket(); * *byte [] m = args[0].getBytes();* *InetAddress aHost = [url removed, login to view](args[1]);* *int serverPort = 6789; * *DatagramPacket request = new DatagramPacket(m, args[0].length(), aHost, serverPort);* *[url removed, login to view](request); * *byte[] buffer = new byte[1000];* *DatagramPacket reply = new DatagramPacket(buffer, [url removed, login to view]);**[url removed, login to view](reply);* *[url removed, login to view]("Reply: " + new String([url removed, login to view]()));** }catch (SocketException e){[url removed, login to view]("Socket: " + [url removed, login to view]());* *}catch (IOException e){[url removed, login to view]("IO: " + [url removed, login to view]());} }finally {if(aSocket != null) [url removed, login to view]();} } }

* *Figure 4.4

UDP server repeatedly receives a request and sends it back to the client

* *import java.net.*; import java.io.*; public class UDPServer{ public static void main(String args[]){ DatagramSocket aSocket = null; try{ aSocket = new DatagramSocket(6789); byte[] buffer = new byte[1000]; while(true){ DatagramPacket request = new DatagramPacket(buffer, [url removed, login to view]); [url removed, login to view](request); DatagramPacket reply = new DatagramPacket([url removed, login to view](), [url removed, login to view](), [url removed, login to view](), [url removed, login to view]()); [url removed, login to view](reply); } }catch (SocketException e){[url removed, login to view]("Socket: " + [url removed, login to view]()); }catch (IOException e) {[url removed, login to view]("IO: " + [url removed, login to view]());} }finally {if(aSocket != null) [url removed, login to view]();} } }

**Figure 4.5

TCP client makes connection to server, sends request and receives reply

* *import java.net.*; import java.io.*; public class TCPClient { public static void main (String args[]) { // arguments supply message and hostname of destination Socket s = null; try{ int serverPort = 7896; s = new Socket(args[1], serverPort); DataInputStream in = new DataInputStream( [url removed, login to view]()); DataOutputStream out = new DataOutputStream( [url removed, login to view]()); [url removed, login to view](args[0]); // UTF is a string encoding see Sn 4.3 String data = [url removed, login to view](); [url removed, login to view]("Received: "+ data) ; }catch (UnknownHostException e){ [url removed, login to view]("Sock:"+[url removed, login to view]()); }catch (EOFException e){[url removed, login to view]("EOF:"+[url removed, login to view]()); }catch (IOException e){[url removed, login to view]("IO:"+[url removed, login to view]());} }finally {if(s!=null) try {[url removed, login to view]();}catch (IOException e){[url removed, login to view]("close:"+[url removed, login to view]());}} } }

**Figure 4.6 TCP server makes a connection for each client and then echoes the client’s request

* *import java.net.*; import java.io.*; public class TCPServer { public static void main (String args[]) { try{ int serverPort = 7896; ServerSocket listenSocket = new ServerSocket(serverPort); while(true) { Socket clientSocket = [url removed, login to view](); Connection c = new Connection(clientSocket); } } catch(IOException e) {[url removed, login to view]("Listen :"+[url removed, login to view]());} } }

**class Connection extends Thread {* *DataInputStream in;* *DataOutputStream out;* *Socket clientSocket;* *public Connection (Socket aClientSocket) {* * try {* *clientSocket = aClientSocket;* *in = new DataInputStream( [url removed, login to view]());* *out =new DataOutputStream( [url removed, login to view]());* *[url removed, login to view]();* * } catch(IOException e) {[url removed, login to view]("Connection:"+[url removed, login to view]());}* *}* *public void run(){* * try {** // an echo server* *String data = [url removed, login to view]();** * *[url removed, login to view](data);* * } catch(EOFException e) {[url removed, login to view]("EOF:"+[url removed, login to view]());* * } catch(IOException e) {[url removed, login to view]("IO:"+[url removed, login to view]());}* * } finally{ try {[url removed, login to view]();}catch (IOException e){/*close failed*/}}* *}* *}*

## Platform

WINDOWS XP

Computer Security Engineering MySQL Oracle PHP Software Architecture Software Testing Web Security

Project ID: #3702541

About the project

6 proposals Remote project Active Aug 9, 2006

6 freelancers are bidding on average $31 for this job

firejumpvw

See private message.

$25.5 USD in 2 days
(54 Reviews)
4.1
checkmyoffering

See private message.

$34 USD in 2 days
(5 Reviews)
3.2
fridaysoft

See private message.

$42.5 USD in 2 days
(8 Reviews)
3.9
randtl

See private message.

$34.85 USD in 2 days
(12 Reviews)
2.6
vasanth127

See private message.

$17 USD in 2 days
(0 Reviews)
0.0
rbpaddy

See private message.

$31.45 USD in 2 days
(0 Reviews)
0.0