Ejemplo n.º 1
0
		/// <summary>
		/// Processes the received packet.
		/// </summary>
		/// <param name="packet">The YMSG packet.</param>
		private void ProcessPacket(Packet packet)
		{
			switch (packet.Service)
			{
				case PacketService.YAHOO_SERVICE_Y8_LIST:
					break;
				case PacketService.YAHOO_SERVICE_LIST:
					this.LoginStatus = LoginStatus.Success;
					break;
				case PacketService.YAHOO_SERVICE_NOTIFY:
					break;
				case PacketService.YAHOO_SERVICE_MESSAGE:
					Console.WriteLine(ByteArray.ToString(packet.Data[14]));
					break;
			}
			
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Sends and receives packet synchronously.
		/// </summary>
		/// <param name="packet">The request packet.</param>
		/// <returns>The response packet.</returns>
		private Packet SendAndReceivePacket(Packet packet)
		{
			//
			// Sends
			var buf = new byte[BUFFER_SIZE];
			int len = packet.Write(buf, 0);
			
			this.Stream.Write(buf, 0, len);
			
			//
			// Receives
			len = this.Stream.Read(buf, 0, BUFFER_SIZE);
			var resp = new Packet();
			resp.Read(buf, 0, len);
			return resp;
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Sends a YMSG packet.
		/// </summary>
		/// <param name="packet">The YMSG packet.</param>
		private IAsyncResult SendPacket(Packet packet)
		{
			var buf = new byte[BUFFER_SIZE];
			int len = packet.Write(buf, 0);
			return this.Stream.BeginWrite(buf, 0, len, new AsyncCallback(this.OnDataSent), null);
		}
Ejemplo n.º 4
0
		/// <summary>
		/// Handles the received data.
		/// </summary>
		private void OnDataReceived(IAsyncResult r)
		{
			var info = (ReadAsyncData)r.AsyncState;
			int len = info.Stream.EndRead(r);
			this.ReadyToReceive();
//			if(len>650){
//				return;
//			}
			//
			// Reads the packet.
			var packet = new Packet();
			packet.Read(info.Buffer, 0, len);
			this.ProcessPacket(packet);
		}