public void Listen(UDPSetting setting) { if (null == setting) { NetDebug.Error("[UDPConnection] the setting can not be null."); return; } this.setting = setting; Initialize(this.setting.ioNum); localEndPoint = NetUtility.GetIPEndPoint(setting.host, setting.port); socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.ReuseAddress, true); socket.Bind(localEndPoint); kcpHandle = new KCPServerHandle(setting); kcpHandle.onSendHandle = OnSend; kcpHandle.onReceiveHandle = OnReceive; Start(); }
public override void Invoke(AMFContext context) { AMFMessage aMFMessage = context.AMFMessage; AMFHeader header = aMFMessage.GetHeader("amf_server_debug"); if (header != null) { ASObject content = header.Content as ASObject; AMFBody bodyAt = aMFMessage.GetBodyAt(aMFMessage.BodyCount - 1); ResponseBody body = new ResponseBody { Target = bodyAt.Response + "/onDebugEvents", Response = null, IsDebug = true }; ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); list.Add(list2); if ((bool)content["httpheaders"]) { list2.Add(new HttpHeader()); } if ((bool)content["amfheaders"]) { list2.Add(new AMFRequestHeaders(aMFMessage)); } ArrayList traceStack = NetDebug.GetTraceStack(); if ((((bool)content["trace"]) && (traceStack != null)) && (traceStack.Count > 0)) { ArrayList list4 = new ArrayList(traceStack); list2.Add(new TraceHeader(list4)); NetDebug.Clear(); } body.Content = list; context.MessageOutput.AddBody(body); } NetDebug.Clear(); }
public void Copy(byte[] data, int offset, int count) { if (null == data) { NetDebug.Error("[DynamicBuffer] Copy, the data can not be null."); return; } int reserveBytesLength = GetReserveBytesLength(); if (reserveBytesLength >= count) { System.Buffer.BlockCopy(data, offset, buffer, usedLength, count); } else { int size = buffer.Length + count - reserveBytesLength; byte[] alloc = new byte[size]; System.Buffer.BlockCopy(buffer, 0, alloc, 0, usedLength); System.Buffer.BlockCopy(data, offset, alloc, usedLength, count); buffer = alloc; } usedLength += count; }
public void Copy(byte[] data, int offset, int count) { if (null == data) { NetDebug.Error("[MemoryBufferStream] copy, the data can not be null."); return; } int freeLength = GetFreeLength(); if (freeLength >= count) { System.Buffer.BlockCopy(data, offset, buffer, length, count); } else { int size = buffer.Length + count - freeLength; byte[] alloc = new byte[size]; System.Buffer.BlockCopy(buffer, 0, alloc, 0, length); System.Buffer.BlockCopy(data, offset, alloc, length, count); buffer = alloc; } length += count; }
public void Connect(string address, int port) { Initialize(); IsServer = false; State = UDPConnectionState.OPENING; remoterPoint = NetUtility.GetIPEndPoint(address, port); if (null == remoterPoint) { NetDebug.Log("[TCPClient] remote can not be null."); return; } socket = new Socket(remoterPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp); socket.Connect(remoterPoint); ReceiveFromAsync(remoterPoint); //socket.Blocking = setting.blocking; //socket.NoDelay = setting.noDelay; Send(remoterPoint, UDPPacketType.SYN); }
internal IMessage RouteMessage(IMessage message, IEndpoint endpoint) { IService service = null; object obj2 = null; IMessage errorMessage = null; Exception exception2; CommandMessage message3 = message as CommandMessage; if ((message3 != null) && ((message3.operation == 8) || (message3.operation == 9))) { log.Debug(string.Format("Routing CommandMessage operation = {0}", message3.operation)); try { errorMessage = this.GetService("authentication-service").ServiceMessage(message3) as IMessage; } catch (SecurityException exception) { if (log.get_IsDebugEnabled()) { log.Debug(exception.Message); } errorMessage = ErrorMessage.GetErrorMessage(message, exception); } catch (Exception exception4) { exception2 = exception4; if (log.get_IsErrorEnabled()) { log.Error(__Res.GetString("MessageBroker_RoutingError"), exception2); } errorMessage = ErrorMessage.GetErrorMessage(message, exception2); } } else if ((message3 != null) && (message3.operation == 5)) { log.Debug("Routing CommandMessage ping"); errorMessage = new AcknowledgeMessage { body = true }; } else { log.Debug(string.Format("Routing message {0}", message.GetType().Name)); if (FluorineContext.Current != null) { FluorineContext.Current.RestorePrincipal(this.LoginCommand); } service = this.GetService(message); if (service != null) { try { service.CheckSecurity(message); obj2 = service.ServiceMessage(message); } catch (UnauthorizedAccessException exception3) { if (log.get_IsDebugEnabled()) { log.Debug(exception3.Message); } obj2 = ErrorMessage.GetErrorMessage(message, exception3); } catch (Exception exception6) { exception2 = exception6; if (log.get_IsErrorEnabled()) { log.Error(exception2.Message, exception2); } obj2 = ErrorMessage.GetErrorMessage(message, exception2); } } else { string str = __Res.GetString("Destination_NotFound", new object[] { message.destination }); if (log.get_IsErrorEnabled()) { log.Error(str); } obj2 = ErrorMessage.GetErrorMessage(message, new FluorineException(str)); } if (obj2 is IMessage) { errorMessage = obj2 as IMessage; } else { errorMessage = new AcknowledgeMessage { body = obj2 }; } } if (errorMessage is AsyncMessage) { ((AsyncMessage)errorMessage).correlationId = message.messageId; } errorMessage.destination = message.destination; errorMessage.clientId = message.clientId; if (message.HeaderExists("amf_server_debug")) { log.Debug("MessageBroker processing debug header"); ArrayList traceStack = NetDebug.GetTraceStack(); errorMessage.SetHeader("amf_server_debug", traceStack.ToArray(typeof(object)) as object[]); NetDebug.Clear(); } if ((FluorineContext.Current != null) && (FluorineContext.Current.Client != null)) { errorMessage.SetHeader("DSId", FluorineContext.Current.Client.Id); } return(errorMessage); }
/// <summary> /// Call this method in order to send a message from your code into the message routing system. /// The message is routed to a service that is defined to handle messages of this type. /// Once the service is identified, the destination property of the message is used to find a destination configured for that service. /// The adapter defined for that destination is used to handle the message. /// </summary> /// <param name="message">The message to be routed to a service.</param> /// <param name="endpoint">This can identify the endpoint that is sending the message but it is currently not used so you may pass in null.</param> /// <returns>The result of the message routing.</returns> internal IMessage RouteMessage(IMessage message, IEndpoint endpoint) { IService service = null; object result = null; IMessage responseMessage = null; if (log.IsDebugEnabled) { log.Debug(__Res.GetString(__Res.MessageBroker_RoutingMessage, message.ToString())); } CommandMessage commandMessage = message as CommandMessage; if (commandMessage != null && (commandMessage.operation == CommandMessage.LoginOperation || commandMessage.operation == CommandMessage.LogoutOperation)) //Login, Logout { try { service = GetService(AuthenticationService.ServiceId); result = service.ServiceMessage(commandMessage); responseMessage = result as IMessage; } catch (UnauthorizedAccessException uae) { if (log.IsDebugEnabled) { log.Debug(uae.Message); } responseMessage = ErrorMessage.GetErrorMessage(message, uae); } catch (SecurityException exception) { if (log.IsDebugEnabled) { log.Debug(exception.Message); } responseMessage = ErrorMessage.GetErrorMessage(message, exception); } catch (Exception exception) { if (log.IsErrorEnabled) { log.Error(__Res.GetString(__Res.MessageBroker_RoutingError), exception); } responseMessage = ErrorMessage.GetErrorMessage(message, exception); } } else if (commandMessage != null && commandMessage.operation == CommandMessage.ClientPingOperation) { responseMessage = new AcknowledgeMessage(); responseMessage.body = true; } else { //The only case when context is not set should be when one starts a new thread in the backend //if( FluorineContext.Current != null ) // FluorineContext.Current.RestorePrincipal(this.LoginCommand); _loginManager.RestorePrincipal(); service = GetService(message); if (service != null) { try { service.CheckSecurity(message); result = service.ServiceMessage(message); } catch (UnauthorizedAccessException uae) { if (log.IsDebugEnabled) { log.Debug(uae.Message); } result = ErrorMessage.GetErrorMessage(message, uae); } catch (SecurityException exception) { if (log.IsDebugEnabled) { log.Debug(exception.Message); } result = ErrorMessage.GetErrorMessage(message, exception); } catch (ServiceException exception) { if (log.IsDebugEnabled) { log.Debug(exception.Message); } result = ErrorMessage.GetErrorMessage(message, exception); } catch (Exception exception) { if (log.IsErrorEnabled) { log.Error(exception.Message, exception); } result = ErrorMessage.GetErrorMessage(message, exception); } } else { string msg = __Res.GetString(__Res.Destination_NotFound, message.destination); if (log.IsErrorEnabled) { log.Error(msg); } result = ErrorMessage.GetErrorMessage(message, new FluorineException(msg)); } if (!(result is IMessage)) { responseMessage = new AcknowledgeMessage(); responseMessage.body = result; } else { responseMessage = result as IMessage; } } if (responseMessage is AsyncMessage) { ((AsyncMessage)responseMessage).correlationId = message.messageId; } responseMessage.destination = message.destination; responseMessage.clientId = message.clientId; //Debug if (message.HeaderExists(AMFHeader.DebugHeader)) { log.Debug("MessageBroker processing debug header"); ArrayList traceStack = NetDebug.GetTraceStack(); responseMessage.SetHeader(AMFHeader.DebugHeader, traceStack.ToArray(typeof(object)) as object[]); NetDebug.Clear(); } //The only case when we do not have context should be when the server side initiates a push if (FluorineContext.Current != null && FluorineContext.Current.Client != null) { responseMessage.SetHeader(MessageBase.FlexClientIdHeader, FluorineContext.Current.Client.Id); } if (log.IsDebugEnabled) { log.Debug(__Res.GetString(__Res.MessageBroker_Response, responseMessage.ToString())); } return(responseMessage); }
protected override void HandleValue(ServerContext context, ParserResult result) { NetDebug.GenerateDebugFile(); }
void Awake() { netDebug = this; }