Package ch.usi.dslab.bezerra.netwrapper.tcp

Examples of ch.usi.dslab.bezerra.netwrapper.tcp.TCPSender


import ch.usi.dslab.bezerra.netwrapper.tcp.TCPSender;

public class SimpleTcpClientSenderReceiver {

   public static void main(String[] args) throws InterruptedException, IOException {
      TCPSender sender = new TCPSender();
     
      Message message = new Message(new String("first message from client"));
      TCPConnection serverConnection = new TCPConnection("localhost", 50000);

      sender.send(message, serverConnection);

      TCPReceiver receiver = new TCPReceiver();
      receiver.addConnection(serverConnection);

      TCPMessage msg = receiver.receive();
      String reply = (String) msg.getContents().getItem(0);
      System.out.println("Reply received: " + reply);

      Message message2 = new Message(new String("second message from client"));

      sender.send(message2, serverConnection);

      TCPMessage msg2 = receiver.receive();
      String reply2 = (String) (msg2.getContents().getItem(0));
      System.out.println("Reply received: " + reply2);
     
      sender.stop();
      receiver.stop();
   }
View Full Code Here


public class SimpleTcpServer {
  
   public static void main(String[] args) {
      TCPReceiver receiver = new TCPReceiver(50000);
      TCPSender   sender   = new TCPSender  ();
     
      while(!Thread.interrupted()) {
         TCPMessage msg = receiver.receive();
         String recvdMessage = (String) msg.getContents().getItem(0);
         System.out.println("Received message: " + recvdMessage);
         Message ack = new Message(new String("Ack for message \"" + recvdMessage + "\""));
         sender.send(ack, msg.getConnection());
      }
   }
View Full Code Here

TOP

Related Classes of ch.usi.dslab.bezerra.netwrapper.tcp.TCPSender

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.