public SocketState(Socket sock, TransportLayerCommunicator transportLayerCommunicator, Object obj)
 {
         this.sock = sock;
         this.transportLayerCommunicator = transportLayerCommunicator;
         this.obj = obj;
 }
 public SocketState(Socket sock, TransportLayerCommunicator transportLayerCommunicator)
 {
         this.sock = sock;
         this.transportLayerCommunicator = transportLayerCommunicator;
 }
 static private void notifyUpperLayer(String content, Socket fromSock, TransportLayerCommunicator transportLayerCommunicator)
 {
         Console.WriteLine("TransportLayerCommunicator::notifyUpperLayer ENTER");
         String[] split = content.Split(new char[] {'\0'});
        
         String strFromIP = null, strToIP, strCallType = null, strclientGuid, strBuffer;
         Guid clientGuid = new Guid();;
         byte[] byteBuffer, byteclientGuid; ;
         MsgExtractionStatus msgExtractionStatus = MsgExtractionStatus.NOTHING_EXTRACTED;  
        
         foreach (String s in split)
         {
                 if(msgExtractionStatus == MsgExtractionStatus.NOTHING_EXTRACTED || msgExtractionStatus == MsgExtractionStatus.MESSAGE_EXTRACTED)
                 {
                         if(s.Length == 0)
                                 break;
                         strFromIP = s;          
                         Console.WriteLine("FromIP received: {0}", s);
                         msgExtractionStatus = MsgExtractionStatus.FROM_IP_EXTRACTED;
                        
                 }
                 else if(msgExtractionStatus == MsgExtractionStatus.FROM_IP_EXTRACTED)
                 {
                         strToIP = s;    
                         Console.WriteLine("ToIP received: {0}", s);
                         msgExtractionStatus = MsgExtractionStatus.TO_IP_EXTRACTED;
                 }
                 else if(msgExtractionStatus == MsgExtractionStatus.TO_IP_EXTRACTED)
                 {
                         strCallType = s;
                         Console.WriteLine("haha 1\n{0}\n{1}", s, s.Length);
                         msgExtractionStatus = MsgExtractionStatus.CALLTYPE_EXTRACTED;
                 }
                 else if(msgExtractionStatus == MsgExtractionStatus.CALLTYPE_EXTRACTED)
                 {
                         strclientGuid = s;
                         Console.WriteLine("haha 1.5\n{0}\n{1}", s, s.Length);
                         byteclientGuid = System.Text.Encoding.ASCII.GetBytes(strclientGuid);
                         clientGuid = new Guid(s);
                         msgExtractionStatus = MsgExtractionStatus.clientGuid_EXTRACTED;
                 }
                 else if(msgExtractionStatus == MsgExtractionStatus.clientGuid_EXTRACTED)
                 {
                         strBuffer = s;
                         Console.WriteLine("haha 2\n{0}\n{1}", s, s.Length);
                         byteBuffer = System.Text.Encoding.ASCII.GetBytes(strBuffer);
                         IPAddress fromIP = UtilityMethod.convertStrToIP(strFromIP);
                         Console.WriteLine("before ONE-WAY decision");
                         if(String.Compare(strCallType, CallType.ONE_WAY.ToString()) == 0)
                         {
                         	Console.WriteLine("TransportLayerCommunicator::notifyUpperLayer CallType IS ONE_WAY transportLayerCommunicator={0}", transportLayerCommunicator);
                         	if(transportLayerCommunicator == null)
                         		Console.WriteLine("aiyoo");
                         	transportLayerCommunicator.receive(fromIP, clientGuid, byteBuffer, 0, byteBuffer.Length);
                         }
                         else
                         {
                                 Console.WriteLine("TransportLayerCommunicator::notifyUpperLayer CallType IS NOT ONE_WAY");
                                 transportLayerCommunicator.receiveTwoWay(fromIP, clientGuid, byteBuffer, 0, byteBuffer.Length, strCallType);
                         }
                        
                         msgExtractionStatus = MsgExtractionStatus.MESSAGE_EXTRACTED;
                 }
         }
 }
  static private void notifyUpperLayer(String content, Socket fromSock, TransportLayerCommunicator transportLayerCommunicator)
  {
          Console.WriteLine("TransportLayerCommunicator::notifyUpperLayer ENTER");
      Console.WriteLine("TransportLayerCommunicator::DEEPCHK overlayRegistry count = {0}", overlayRegistry.Count);
                 
          String[] split = content.Split(new char[] {'\0'});
      String strclientGuid, strBuffer;
      byte[] byteclientGuid, byteBuffer;
      Guid clientGuid = new Guid();;
      bool readytoNotify = false;  
 
      foreach (String s in split)
      {
          if(readytoNotify == false)
          {
              if(s.Length == 0)
                  break;
              strclientGuid = s;
              Console.WriteLine("haha 1\n{0}\n{1}", s, s.Length);
              byteclientGuid = System.Text.Encoding.ASCII.GetBytes(strclientGuid);
              clientGuid = new Guid(s);
              readytoNotify = true;
          }
          else if(readytoNotify == true)
          {
              strBuffer = s;
              Console.WriteLine("haha 2\n{0}\n{1}", s, s.Length);
                                  byteBuffer = System.Text.Encoding.ASCII.GetBytes(strBuffer);
               
              IPAddress fromIP = ((IPEndPoint)(fromSock.RemoteEndPoint)).Address;
              transportLayerCommunicator.receive(fromIP, clientGuid, byteBuffer, 0, byteBuffer.Length);
              readytoNotify = false;
          }
     }
 }
  private readonly TransportLayerCommunicator transportLayerCommunicator; // = TransportLayerCommunicator.getRefTransportLayerCommunicator();
 
  public SockMsgQueue(IPAddress IP, TransportLayerCommunicator transportLayerCommunicator)
  {
          this.transportLayerCommunicator = transportLayerCommunicator;
          this.IP = IP;
          sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
          connectionState = ConnectionState.NOT_CONNECTED;
  }
 public SockMsgQueue(Socket sock, TransportLayerCommunicator transportLayerCommunicator)
 {
         this.transportLayerCommunicator = transportLayerCommunicator;
         this.sock = sock;
         this.IP = ((IPEndPoint)(sock.RemoteEndPoint)).Address;
         if(sock.Connected)
                 connectionState = ConnectionState.CONNECTED;
         else
                 connectionState = ConnectionState.NOT_CONNECTED;
                
 }
                public static TransportLayerCommunicator getRefTransportLayerCommunicator()
                {
                        Console.WriteLine("TransportLayerCommunicator::getRefTransportLayerCommunicator ENTER");
#if SIM
                        Console.WriteLine("IPAddress= {0}   Port={1}", UtilityMethod.GetLocalHostIP().ToString(), UtilityMethod.GetPort());
                                               
                        TransportLayerCommunicator transportLayerCommunicator;
                        lock(transportLayerCommunicatorRegistryLock)
                        {
                                if(!(transportLayerCommunicatorRegistry.TryGetValue(UtilityMethod.GetLocalHostIP().ToString(), out transportLayerCommunicator)))
                                {
                                        transportLayerCommunicator = new TransportLayerCommunicator();
                                        transportLayerCommunicatorRegistry.Add(UtilityMethod.GetLocalHostIP().ToString(), transportLayerCommunicator);
                                }
                        }
                        return transportLayerCommunicator;
                       
                       
#else
                        lock(transportLayerCommunicatorLock)
                        {
                                if(transportLayerCommunicator!=null)
                                        return transportLayerCommunicator;
                                else
                                {
                                        transportLayerCommunicator = new TransportLayerCommunicator();
                                        return transportLayerCommunicator;
                                }
                        }
#endif
                }
예제 #8
0
파일: Boxit.cs 프로젝트: ratulmukh/tashjik
    private static void notifyUpperLayer(String content, Socket fromSock, TransportLayerCommunicator transportLayerCommunicator)
    {
        Console.WriteLine("Boxit::notifyUpperLayer ENTER");
                        Console.WriteLine("Boxit::notifyUpperLayer content=\n{0}", content);
                        Console.WriteLine("Boxit::notifyUpperLayer split contents=");
                        String[] split = content.Split(new char[] {'\0'});
                        foreach (String s in split)
                                Console.WriteLine(s);
                        byte[] byteContent = System.Text.Encoding.ASCII.GetBytes(content);

                        String strFromIP = null;
                        String strToIP = null;
                        String strOverlayGuid = null;
                        String strCallType = null;
                        byte[] byteOverlayGuid;
                        Guid overlayGuid = new Guid();;
                        String strBuffer;
                        byte[] byteBuffer;
                        MsgExtractionStatus msgExtractionStatus = MsgExtractionStatus.NOTHING_EXTRACTED;
                        foreach (String s in split)
                        {
                                if(msgExtractionStatus == MsgExtractionStatus.NOTHING_EXTRACTED || msgExtractionStatus == MsgExtractionStatus.MESSAGE_EXTRACTED)
                                {
                                        if(s.Length == 0)
                                                break;
                                        strFromIP = s;
                                        Console.WriteLine("FromIP received: {0}", s);
                                        msgExtractionStatus = MsgExtractionStatus.FROM_IP_EXTRACTED;

                                }
                                else if(msgExtractionStatus == MsgExtractionStatus.FROM_IP_EXTRACTED)
                                {
                                        strToIP = s;
                                        Console.WriteLine("ToIP received: {0}", s);
                                        msgExtractionStatus = MsgExtractionStatus.TO_IP_EXTRACTED;

                                }
                                else if(msgExtractionStatus == MsgExtractionStatus.TO_IP_EXTRACTED)
                                {
                                        strCallType = s;
                                        Console.WriteLine("haha 1\n{0}\n{1}", s, s.Length);
                                        //byteOverlayGuid = System.Text.Encoding.ASCII.GetBytes(strOverlayGuid);
                                        //overlayGuid = new Guid(s);
                                        msgExtractionStatus = MsgExtractionStatus.CALLTYPE_EXTRACTED;
                                }
                                else if(msgExtractionStatus == MsgExtractionStatus.CALLTYPE_EXTRACTED)
                                {
                                        strOverlayGuid = s;
                                        Console.WriteLine("haha 1.5\n{0}\n{1}", s, s.Length);
                                        byteOverlayGuid = System.Text.Encoding.ASCII.GetBytes(strOverlayGuid);
                                        overlayGuid = new Guid(s);
                                        msgExtractionStatus = MsgExtractionStatus.OVERLAYGUID_EXTRACTED;
                                }
                                else if(msgExtractionStatus == MsgExtractionStatus.OVERLAYGUID_EXTRACTED)
                                {
                                        strBuffer = s;
                                        Console.WriteLine("haha 2 \n {0}\n{1}", s, s.Length);
                                        byteBuffer = System.Text.Encoding.ASCII.GetBytes(strBuffer);

                                        //byte[] byteFromIP = System.Text.Encoding.ASCII.GetBytes(strFromIP);
                                        //IPAddress fromIP = new IPAddress(byteFromIP);

                                        IncomingMsg incomingMsg = new IncomingMsg();
                                        incomingMsg.strFromIP = strFromIP;
                                        incomingMsg.strToIP = strToIP;
                                        incomingMsg.strCallType = strCallType;
                                        incomingMsg.strOverlayGuid = strOverlayGuid;
                                        incomingMsg.extractedMsg = strBuffer;
                                        incomingMsg.completeMsg = byteContent;
                                        incomingMsg.offset = 0;
                                        incomingMsg.size = byteContent.Length;
                                        ParameterizedThreadStart processMsgJob = new ParameterizedThreadStart(processMsg);
                                        Thread processMsgThread = new Thread(processMsgJob);
                                        processMsgThread.Start(incomingMsg);
                                        //processMsg(strFromIP, strToIP, strOverlayGuid, strBuffer, byteContent, 0, byteContent.Length);
                                        msgExtractionStatus = MsgExtractionStatus.MESSAGE_EXTRACTED;
                                }
                        }
    }
예제 #9
0
		static TransportLayerCommunicator transportLayerCommunicator; // = TransportLayerCommunicator.getRefTransportLayerCommunicator();

#if SIM		
		public static void Main(string[] args) 
		{
			Console.WriteLine("hello");
			//Console.WriteLine(args.Length);
		
			if(args.Length >= 1)
			{
				//byte[] byteIP = System.Text.Encoding.ASCII.GetBytes(args[0]);
				String[] IPsplit = args[0].Split(new char[] {'.'});
				Console.WriteLine("Hi there");

				IPAddress ipAddress = UtilityMethod.convertStrToIP(args[0]);
				
				UtilityMethod.SetLocalHostIP(ipAddress);
				Console.Write("received port=");
				Console.WriteLine(args[1]);
				UtilityMethod.SetPort(args[1]);
				
				transportLayerCommunicator = TransportLayerCommunicator.getRefTransportLayerCommunicator();
				
			}
예제 #10
0
 public ProxyNodeController(CreateProxyNodeDelegate createProxyNodeDelegate, Guid overlayInstanceGuid)
 {
     Console.WriteLine("ProxyNodeController::ProxyNodeController ENTER");
     this.overlayInstanceGuid = overlayInstanceGuid;
     this.createProxyNodeDelegate = createProxyNodeDelegate;
     transportLayerCommunicator = Tier0.TransportLayerCommunicator.getRefTransportLayerCommunicator();
     transportLayerCommunicator.register(overlayInstanceGuid, this);
 }
예제 #11
0
파일: Client.cs 프로젝트: ratulmukh/tashjik
		static TransportLayerCommunicator transportLayerCommunicator; // = TransportLayerCommunicator.getRefTransportLayerCommunicator();

#if SIM		
		public static void Main(string[] args) 
		{
			Console.WriteLine("hello");
			//Console.WriteLine(args.Length);
		
			if(args.Length >= 1)
			{
				//byte[] byteIP = System.Text.Encoding.ASCII.GetBytes(args[0]);
				String[] IPsplit = args[0].Split(new char[] {'.'});
				Console.WriteLine("Hi there");

				IPAddress ipAddress = UtilityMethod.convertStrToIP(args[0]);
				
				UtilityMethod.SetLocalHostIP(ipAddress);
				Console.Write("received port=");
				Console.WriteLine(args[1]);
				UtilityMethod.SetPort(args[1]);
				
				transportLayerCommunicator = TransportLayerCommunicator.getRefTransportLayerCommunicator();
				
				//FileAppender fileAppender = new FileAppender();
				//	fileAppender.File = "E:/manga";
				//BasicConfigurator.Configure(fileAppender);
				//log.Info("hi");
				//string fn = @"e:\ratul\code\tashjik\logs\" + args[0]+ ".txt";
				//TextWriter errStream = new StreamWriter(fn);
				//Console.SetError(errStream);
				//Console.SetOut(errStream);
			}