public void SendMessage(string message, SocketEventHandler OnReceiveMessage) { if (IsLogined == true) { socketManager.SendData(loginSocket, user_id + "#" + message, OnReceiveMessage); } }
void Start() { Debug.Log("das"); socketEventHandler = new SocketEventHandler(this); if (SharedArea.id != -1 && !SharedArea.isLoggedIn) { Debug.Log("ID: " + SharedArea.id + "\t\tNickname: " + SharedArea.nickname); SharedArea.socketClient = new SocketClient(); SharedArea.socketClient.SetSocketEventListener(socketEventHandler); SharedArea.socketClient.Connect(Config.SERVER_IP, Config.GAME_SERVER_PORT); StartCoroutine(SharedArea.socketClient.DataReceiveCorutine()); StartCoroutine(SharedArea.socketClient.DataSendCorutine()); LoginToGameServer(); } else if (SharedArea.isLoggedIn) { SharedArea.socketClient.SetSocketEventListener(socketEventHandler); StartCoroutine(SharedArea.socketClient.DataReceiveCorutine()); StartCoroutine(SharedArea.socketClient.DataSendCorutine()); RequestUserList(); RequestRoomList(); } }
public int Connect(string ip, int port, SocketEventHandler handler) { try { m_ip = ip; m_port = port; this.eventHandler = handler; IPAddress ipAddress = Dns.GetHostEntry(ip).AddressList[0]; IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, port); client.Connect(ipEndPoint); //error_id = NETWORK_CONNECTED; BinaryPack header = new BinaryPack(PACKET_HEAD_SIZE); client.GetStream().BeginRead(header.buffer, 0, PACKET_HEAD_SIZE, new AsyncCallback(DoReadPacketHeader), header); return(0); } catch (SocketException ex) { error_id = NETWORK_CONNECT_ERROR; res = ex.Message; return(-1); } catch (System.Security.SecurityException se) { error_id = NETWORK_CONNECT_ERROR; res = se.Message; return(-1); } }
public static void AddServerEventHandler(string serverName, SocketEventHandler socketEventHandler) { INetServer server = GetServer(serverName); if (server != null) { server.OnSocketEvent += socketEventHandler; } }
private void DoPong(SocketEventArgs e) { SocketEventHandler handler = OnPong; if (handler != null) { handler(this, e); } }
public void On(string eventname, SocketEventHandler handler) { _handlers[eventname] = handler; #if UNITY_EDITOR || UNITY_STANDALONE _socket.On(eventname, OnRawEvent); #else Application.ExternalCall("OnEvent", _objectName, eventname, handler.Method.Name); #endif }
/// <summary> /// /// </summary> /// <param name="e"></param> protected void TriggerClosed(SocketEventArgs e) { SocketEventHandler handler = OnClosed; if (handler != null) { handler(this, e); } }
void OnRawEvent(SocketIOEvent e) { SocketEventHandler h = _handlers[e.name]; if (h != null) { h(e.data.ToString()); } }
/// <summary> /// /// </summary> /// <param name="e"></param> protected void TriggerMessage(SocketEventArgs e) { SocketEventHandler handler = OnMessage; if (handler != null) { handler(this, e); } }
public static void AddClientEventHandler(string clientName, SocketEventHandler socketEventHandler) { INetClient client = GetClient(clientName); if (client != null) { client.OnSocketEvent += socketEventHandler; } }
/// <summary> /// /// </summary> /// <param name="e"></param> protected virtual void TriggerError(SocketEventArgs e) { SocketEventHandler handler = OnError; if (handler != null) { handler(this, e); } }
private void OnConstructing(TcpClientOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (options.RemoteEndPoint == null) { throw new ArgumentNullException(nameof(options.RemoteEndPoint)); } connection = new TcpConnection(options.RemoteEndPoint, options.LocalEndPoint) { OnConnected = OnConnectedHandler, OnReceived = OnReceivedHandler, OnDisconnected = OnDisconnectedHandler, OnStarted = OnStartedHandler, OnStopped = OnStoppedHandler, OnException = OnExceptionHandler, ConnectTimeout = options.ConnectTimeout, OnTryConnecting = OnTryConnectingHandler, ReconnectEnable = options.ReconnectEnable, TryConnectionStrategy = options.TryConnectionStrategy }; connection.KeepAlive(KeepAliveOption.KeepAlive, KeepAliveOption.Interval, KeepAliveOption.Span); if (options.Id > 0) { connection.Id = options.Id; } if (!options.Name.IsNullOrWhiteSpace()) { connection.Name = options.Name; } if (options.OnConnected != null) { this.OnConnected = options.OnConnected; } if (options.OnReceived != null) { this.OnReceived = options.OnReceived; } if (options.OnDisconnected != null) { this.OnDisconnected = options.OnDisconnected; } if (options.OnStarted != null) { this.OnStarted = options.OnStarted; } if (options.OnStopped != null) { this.OnStopped = options.OnStopped; } if (options.OnException != null) { this.OnException = options.OnException; } if (options.OnTryConnecting != null) { this.OnTryConnecting = options.OnTryConnecting; } }
public void Process(int eventID, NetInfo obj) { if (eventID == 0) { return; } ProcessEvent(eventID, obj); SocketEventHandler.ProcEvent((uint)eventID, obj); }
void Update() { if (SharedArea.isLoggedIn) { socketEventHandler = new SocketEventHandler(this); SharedArea.socketClient.SetSocketEventListener(socketEventHandler); StartCoroutine(SharedArea.socketClient.DataReceiveCorutine()); StartCoroutine(SharedArea.socketClient.DataSendCorutine()); } }
public void UnRegistEventHandler(ESocketEventType eventType, SocketEventHandler callback) { if (mSocketEventDic != null && mSocketEventDic.ContainsKey((int)eventType)) { mSocketEventDic[(int)eventType] -= callback; if (mSocketEventDic[(int)eventType] == null) { mSocketEventDic.Remove((int)eventType); } } }
private void InvokeSocketEvent(int eventType, string value) { if (mSocketEventDic != null && mSocketEventDic.ContainsKey(eventType)) { SocketEventHandler callback = mSocketEventDic[eventType]; if (callback != null) { callback.Invoke(value); } } }
internal void QueueEvent(SocketEventHandler socketEvent) { _eventQueue.Enqueue(socketEvent); _eventCount.Release(); var bufferAvailable = BufferAvailable; if (bufferAvailable != null) { bufferAvailable(this, new BufferAvailableArgs()); } }
public void Connect(Socket socket, string address, int port, SocketEventHandler OnConnected) { IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(address), port); socket.BeginConnect(ipep, (s) => { OnConnected(200); Debug.WriteLine(ipep.Address + ":" + ipep.Port + " 서버 연결됨"); }, socket); Debug.WriteLine(address + "서버 연결 시작"); }
void Start() { socketEventHandler = new SocketEventHandler(this); socketClient = new SocketClient(); socketClient.SetSocketEventListener(socketEventHandler); ConnectToServer(); StartCoroutine(socketClient.DataReceiveCorutine()); StartCoroutine(socketClient.DataSendCorutine()); }
/// <summary> /// 소켓 인증하기 /// </summary> /// <param name="tokenInfo">사용자 TokenInfo</param> /// <returns></returns> //public void Authentication(TokenInfo tokenInfo) //{ // var data = new JObject(); // data["token"] = tokenInfo.Token; // data["device"] = "pc"; // Emit("authentication", data); // Debug.WriteLine("소켓 인증시도중"); //} /// <summary> /// 소켓이 인증 성공 및 연결 유지 /// </summary> /// <param name="socketEventHandler"></param> /// <returns></returns> //public void Authenticated(SocketEventHandler socketEventHandler) //{ // EventOn("authenticated", (s, e) => // { // Debug.WriteLine("소켓 인증됨"); // socketEventHandler(s, e); // }); //} /// <summary> /// 소켓 인증 실패 및 연결 해제 /// </summary> /// <param name="socketEventHandler"></param> /// <returns></returns> //public void Disconnect(SocketEventHandler socketEventHandler) //{ // EventOn("disconnect", (s, e) => // { // Debug.WriteLine("소켓 인증 실패"); // socketEventHandler(s, e); // }); //} /// <summary> /// 소켓 이벤트 생성 /// </summary> /// <param name="eventString">요청받을 이벤트 이름</param> /// <param name="OnDataGetEnded">요청받은 후 발생시킬 이벤트</param> // TODO : Warning 제거 public void EventOn(Socket socket, string eventString, SocketEventHandler OnDataGetEnded) { socket.On(eventString, (data) => { if (data != null) { if (OnDataGetEnded != null) { OnDataGetEnded(this, data.ToString()); } } }); }
public void RegistSocketEventHandler(ESocketEventType eventType, SocketEventHandler callback) { if (mSocketEventDic != null) { if (mSocketEventDic.ContainsKey((int)eventType)) { mSocketEventDic[(int)eventType] += callback; } else { mSocketEventDic.Add((int)eventType, callback); } } }
void Start() { if (SharedArea.isLoggedIn) { socketEventHandler = new SocketEventHandler(this); SharedArea.socketClient.SetSocketEventListener(socketEventHandler); StartCoroutine(SharedArea.socketClient.DataReceiveCorutine()); StartCoroutine(SharedArea.socketClient.DataSendCorutine()); RequestRoomChiefData(); RequestRoomMemberList(); } }
public TcpClientOptions(IPEndPoint remoteEndPoint, IPEndPoint localEndPoint = null, SocketEventHandler <NetClientReceivedEventArgs <ITcpConnection> > handler = null) { if (localEndPoint != null) { LocalEndPoint = localEndPoint; } if (remoteEndPoint != null) { RemoteEndPoint = remoteEndPoint; } if (handler != null) { OnReceived = handler; } }
public void SendData(Socket socket, string data, SocketEventHandler OnSendCompleted) { if (IsConnected(socket) == false) { OnSendCompleted(500); return; } byte[] bytes = Encoding.UTF8.GetBytes(data); socket.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, (s) => { OnSendCompleted(200); Debug.WriteLine(data + "전송완료"); }, socket); }
public void EventOn(string eventName, SocketEventHandler OnDataGetEnded) { socket.On(eventName, (data) => { if (data != null) { Debug.WriteLine(data); if (OnDataGetEnded != null) { OnDataGetEnded(this, data); } } }); }
public TcpServerOptions(IPEndPoint localEndPoint, int backlog = int.MaxValue, AddressFamily?family = null, SocketEventHandler <NetClientReceivedEventArgs <ITcpConnection> > handler = null) { LocalEndPoint = localEndPoint; if (backlog > 0) { Backlog = backlog; } if (family != null) { Family = family.Value; } if (handler != null) { OnReceived = handler; } }
/// <summary> /// Initializes the UDP server and automatically starts waiting for connections on all available local IP addresses. /// </summary> /// <param name="port">The local port to listen to</param> /// <param name="newClientCallback">The method to call if a client has been found</param> /// <param name="receivedPacketCallback">The method to call if a new packet has been received</param> public UdpServer(int port, SocketEventHandler newClientCallback, DataEventHandler receivedPacketCallback) { // Initialize the listener socket _listener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) { ExclusiveAddressUse = false, EnableBroadcast = true }; // Start listening to any connection made to the specified port _listener.Bind(new IPEndPoint(IPAddress.Any, port)); ClientConnectionRequested += newClientCallback; ReceivedPacket += receivedPacketCallback; Active = true; Receive(); }
/// <summary> /// Initializes the UDP server and automatically starts waiting for connections. /// </summary> /// <param name="hostname">The local IP to listen to</param> /// <param name="port">The local port to listen to</param> /// <param name="newClientCallback">The method to call if a client has been found</param> /// <param name="receivedPacketCallback">The method to call if a new packet has been received</param> public UdpServer(string hostname, int port, SocketEventHandler newClientCallback, DataEventHandler receivedPacketCallback) { if (!IPAddress.TryParse(hostname, out IPAddress ip)) { throw new InvalidCastException($"Could not convert {hostname} to a valid IPAddress instance."); } // Initialize the listener socket _listener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) { ExclusiveAddressUse = false, EnableBroadcast = true }; // Start listening to the specified IP and port _listener.Bind(new IPEndPoint(ip, port)); ClientConnectionRequested += newClientCallback; ReceivedPacket += receivedPacketCallback; Receive(); }
public void Login(string id, SocketEventHandler OnLoginCompleted) { string Id = "@" + id; socketManager.SendData(loginSocket, Id, OnLoginCompleted); }
/// <summary> /// ���幤�������˵�����, ���ڳ�ʼ�� /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmMain_Load(object sender, System.EventArgs e) { // // this.mnuTest.Visible = Config.Default.IsTest; //��ʾ���вɼ��� Gate_ListView_Ini(this.listView_Gate); Pump_ListView_Ini(this.listView_Pump); SetStatusBarText("���¹�����ˮ���Ȳɼ�ϵͳ"); //string[] newpumps = new NewPumpReader().Read(); //if ( newpumps != null ) //{ // SetCsinfoCommunicationProtocol( InfoList_All, newpumps ); //} _socketEvent += new SocketEventHandler(frmMain__socketEvent); threadListen = new Thread(new ThreadStart(ListeningThread)); threadListen.Start(); StartReceiveThread(); //StartUdpServerThread(); // start gprs coll // if (!Run_Stp_Order) SwitchRun(); //_closeConfirm = true; // start importer // _importer = new Importer(); _importer.Start(); }