private static void ConnectAsyncInternal(this EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectedCallback callback, object state) { if (remoteEndPoint is DnsEndPoint) { var dnsEndPoint = (DnsEndPoint)remoteEndPoint; var asyncResult = Dns.BeginGetHostAddresses(dnsEndPoint.Host, OnGetHostAddresses, new DnsConnectState { Port = dnsEndPoint.Port, Callback = callback, State = state, LocalEndPoint = localEndPoint }); if (asyncResult.CompletedSynchronously) OnGetHostAddresses(asyncResult); } else { var e = CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); var socket = new Socket(remoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (localEndPoint != null) { socket.ExclusiveAddressUse = false; socket.Bind(localEndPoint); } socket.ConnectAsync(e); } }
public static void ConnectAsync(this EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectedCallback callback, object state) { var e = CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); #if NETSTANDARD if (localEndPoint != null) { var socket = new Socket(localEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket.ExclusiveAddressUse = false; socket.Bind(localEndPoint); socket.ConnectAsync(e); } else { Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, e); } #else var socket = new Socket(SocketType.Stream, ProtocolType.Tcp); if (localEndPoint != null) { socket.ExclusiveAddressUse = false; socket.Bind(localEndPoint); } socket.ConnectAsync(e); #endif }
private static void ConnectAsyncInternal(this EndPoint remoteEndPoint, ConnectedCallback callback, object state) { if (remoteEndPoint is DnsEndPoint) { var dnsEndPoint = (DnsEndPoint)remoteEndPoint; var asyncResult = Dns.BeginGetHostAddresses(dnsEndPoint.Host, OnGetHostAddresses, new DnsConnectState { Port = dnsEndPoint.Port, Callback = callback, State = state }); if (asyncResult.CompletedSynchronously) { OnGetHostAddresses(asyncResult); } } else { var e = CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); var socket = new Socket(remoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket.ConnectAsync(e); } }
private static void ConnectAsyncInternal(this EndPoint remoteEndPoint, ConnectedCallback callback, object state) { var e = CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); var socket = new Socket(remoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket.ConnectAsync(e); }
private static void ConnectAsyncInternal(this EndPoint remoteEndPoint, ConnectedCallback callback, object state) { if (remoteEndPoint is DnsEndPoint) { // UnityEngine.Debug.LogError("开始连接 socket》》》》》》》》》》》2222" + System.DateTime.Now.Ticks.ToString()); var dnsEndPoint = (DnsEndPoint)remoteEndPoint; var asyncResult = Dns.BeginGetHostAddresses(dnsEndPoint.Host, OnGetHostAddresses, new DnsConnectState { Port = dnsEndPoint.Port, Callback = callback, State = state }); if (asyncResult.CompletedSynchronously) { OnGetHostAddresses(asyncResult); } } else { // UnityEngine.Debug.LogError("开始连接 socket》》》》》》》》》》》11111"+System.DateTime.Now.Ticks.ToString()); var e = CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); var socket = new Socket(remoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket.ConnectAsync(e); } }
private static void ConnectAsyncInternal( EndPoint remoteEndPoint, ConnectedCallback callback, object state) { if (remoteEndPoint is DnsEndPoint) { DnsEndPoint dnsEndPoint = (DnsEndPoint)remoteEndPoint; IAsyncResult hostAddresses = Dns.BeginGetHostAddresses(dnsEndPoint.Host, new AsyncCallback(ConnectAsyncExtension.OnGetHostAddresses), (object)new ConnectAsyncExtension.DnsConnectState() { Port = dnsEndPoint.Port, Callback = callback, State = state }); if (!hostAddresses.CompletedSynchronously) { return; } ConnectAsyncExtension.OnGetHostAddresses(hostAddresses); } else { SocketAsyncEventArgs socketAsyncEventArgs = ConnectAsyncExtension.CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); new global::System.Net.Sockets.Socket(remoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) .ConnectAsync(socketAsyncEventArgs); } }
public static void ConnectAsync( EndPoint remoteEndPoint, ConnectedCallback callback, object state) { ConnectAsyncExtension.ConnectAsyncInternal(remoteEndPoint, callback, state); }
public static void ConnectAsync(this EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectedCallback callback, object state) { //Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, e); //Don't use Socket.ConnectAsync directly because Mono hasn't implement this method if (m_ConnectMethod != null && localEndPoint == null) m_ConnectMethod.Invoke(null, new object[] { SocketType.Stream, ProtocolType.Tcp, CreateSocketAsyncEventArgs(remoteEndPoint, callback, state) }); else { ConnectAsyncInternal(remoteEndPoint, localEndPoint, callback, state); } }
/// <summary> /// Tries to connect to the assigned port. /// </summary> /// <exception cref="IOException">If connecting fails.</exception> override public void Connect() { if (isConnected) { return; } arduinoSerial.Open();//Opening the serial port arduinoSerial.DataReceived += arduinoSerial_DataReceived; isConnected = true; ConnectedCallback?.Invoke(); }
internal void Connect(int nPort, ConnectedCallback fOnConnected, MessageCallback fOnMessage, DisconnectedCallback fOnDisconnected) { _fOnConnected = fOnConnected; _fOnMessage = fOnMessage; _fOnDisconnected = fOnDisconnected; Log("Connecting..."); Socket newSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint iep = new IPEndPoint(IPAddress.Loopback, nPort); newSocket.BeginConnect(iep, new AsyncCallback(OnConnected), newSocket); }
public MainForm() { InitializeComponent(); InitGraph(); this.Text = Title; connectedCB = new ConnectedCallback(DeviceConnectedHandler); ReconnectUSB(); #if (DEBUG) //tabMain.SelectedIndex = 1; #endif }
public static void ConnectAsync(this EndPoint remoteEndPoint, ConnectedCallback callback, object state) { //Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, e); //Don't use Socket.ConnectAsync directly because Mono hasn't implement this method if (m_ConnectMethod != null) { m_ConnectMethod.Invoke(null, new object[] { SocketType.Stream, ProtocolType.Tcp, CreateSocketAsyncEventArgs(remoteEndPoint, callback, state) }); } else { ConnectAsyncInternal(remoteEndPoint, callback, state); } }
private void EventOnConnected(ConnectedCallback callback) { if (callback.Result != EResult.OK) { _logger.Info(String.Format("Connection failed: {0}", callback.Result)); Thread.Sleep(1000); } else { _logger.Info(String.Format("Connection successful - Logging in {0}", UserName)); LogIn(); } }
public static void ConnectSSLAsync(string host, int port, Factory factory, object contextFactory, int timeout, string bindAddress, ConnectedCallback callback, TimeoutCallback timeoutCallback, object state) { TcpClient client = new TcpClient(); IAsyncResult ar = client.BeginConnect(host, port, null, new AsyncConnectState { responseCallback = callback, timeoutCallback = timeoutCallback, client = client, factory = factory, state = state }); ThreadPool.RegisterWaitForSingleObject(ar.AsyncWaitHandle, _ConnectSSL_Callback, ar, timeout, true); }
/// <summary> /// 连接到移动设备 /// </summary> /// <param name="mobileIPAddress"></param> /// <returns></returns> public void ConnectToMobile(string mobileIPAddress, ConnectedCallback onConnectionEvent) { Log.I("mobileIPAddres:{0}", mobileIPAddress); mSocketClient = FlexiSocket.Create(mobileIPAddress, 1366, Protocols.BodyLengthPrefix); mSocketClient.Connected += onConnectionEvent; mSocketClient.Disconnected += OnDisconnected; mSocketClient.Received += OnReceived; mSocketClient.Sent += OnSent; mSocketClient.Connect(); //this.Repeat() // .Delay(1.0f) // .Event(() => { mSocketClient.Connect(); }) // .Begin(); }
internal void Connect(ConnectedCallback fOnConnected, DisconnectedCallback fOnDisconnected) { _fOnConnected = fOnConnected; _fOnDisconnected = fOnDisconnected; Log("Connecting..."); Socket newSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); int nPort = Controller.GetRegistryValue(Globals.Registry.Port, 23763); IPEndPoint iep = new IPEndPoint(IPAddress.Loopback, nPort); newSocket.BeginConnect(iep, new AsyncCallback(OnConnected), newSocket); }
static SocketAsyncEventArgs CreateSocketAsyncEventArgs(EndPoint remoteEndPoint, ConnectedCallback callback, object state) { var e = new SocketAsyncEventArgs(); e.UserToken = new ConnectToken { State = state, Callback = callback }; e.RemoteEndPoint = remoteEndPoint; e.Completed += new EventHandler<SocketAsyncEventArgs>(SocketAsyncEventCompleted); return e; }
private static SocketAsyncEventArgs CreateSocketAsyncEventArgs( EndPoint remoteEndPoint, ConnectedCallback callback, object state) { SocketAsyncEventArgs socketAsyncEventArgs = new SocketAsyncEventArgs(); socketAsyncEventArgs.UserToken = (object)new ConnectAsyncExtension.ConnectToken() { State = state, Callback = callback }; socketAsyncEventArgs.RemoteEndPoint = remoteEndPoint; socketAsyncEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(ConnectAsyncExtension.SocketAsyncEventCompleted); return(socketAsyncEventArgs); }
private void CheckConnection() { runChecker = true; refreshRequested = true; while (runChecker) { if (Monitor.TryEnter(arduinoConnection)) { try { if (!Send("1000")) { DisconnectedCallback?.Invoke(); TryConnect(); IsConnected = false; } else { ConnectedCallback?.Invoke(); IsConnected = true; } } finally { if (Monitor.IsEntered(arduinoConnection)) { Monitor.Exit(arduinoConnection); } } } int sleeptFor = 0; while (++sleeptFor < 2000) { if (refreshRequested) { refreshRequested = false; break; } Thread.Sleep(1); } } }
/// <summary> /// 连接到移动设备 /// </summary> /// <param name="mobileIPAddress"></param> /// <returns></returns> public void ConnectToMobile(string mobileIPAddress, ConnectedCallback onConnectionEvent) { Log.I("mobileIPAddres:{0}", mobileIPAddress); mSocketClient = FlexiSocket.Create(mobileIPAddress, 1366, Protocols.BodyLengthPrefix); mSocketClient.Connected += onConnectionEvent; mSocketClient.Disconnected += OnDisconnected; mSocketClient.Received += OnReceived; mSocketClient.Sent += OnSent; DelayNode delayNode = new DelayNode(1.0f) { OnEndedCallback = delegate { mSocketClient.Connect(); } }; StartCoroutine(delayNode.Execute()); }
void ConnectToIp(string aIp) { NetPeer newConnection = new NetPeer(); newConnection.StartConnection(aIp); NetPoster.Instance.Connection = newConnection; myIsNetworking = true; myIsHosty = false; //myGUICaretaker.GetGUI<Text>("Connectingy").SetVisibility(EGUIVisibility.Visible); says "connectingy..." myConnectedCallback = () => { MatchInfo matchInfo = new MatchInfo(); matchInfo.myMatchType = EMatchType.Client; myStateStack.AddCommand(new StateCommand { myCommandType = EStateCommandType.Add, myStateType = EStateType.Major, myState = new GameState(matchInfo) }); }; }
public bool CreateGameStaet() { NetHost host = new NetHost(); host.StartListen(); NetPoster.Instance.Connection = host; myIsNetworking = true; myIsHosty = true; myGUICaretaker.GetGUI <Text>("Hosthost").SetVisibility(EGUIVisibility.Visible); myConnectedCallback = () => { MatchInfo matchInfo = new MatchInfo(); matchInfo.myMatchType = EMatchType.Host; myStateStack.AddCommand(new StateCommand { myCommandType = EStateCommandType.Add, myStateType = EStateType.Major, myState = new GameState(matchInfo) }); }; return(true); }
/// <summary> /// 处理连接之后的事件 /// </summary> /// <param name="e"></param> private void ProcessConnectHandler(SocketAsyncEventArgs e) { try { isConnected = (e.SocketError == SocketError.Success); if (isConnected) { e.SetBuffer(receiveBuffer, 0, blockSize); if (!clientSocket.ReceiveAsync(e)) { ProcessReceiveHandler(e); } } ConnectedCallback?.Invoke(e.UserToken as SocketToken, isConnected); } catch (Exception ex) { throw ex; } }
public static void ConnectSSLAsync(string host, int port, Factory factory, object contextFactory, int timeout, ConnectedCallback callback, TimeoutCallback timeoutCallback, object state) { ConnectSSLAsync(host, port, factory, contextFactory, timeout, null, callback, timeoutCallback, state); }
public static void ConnectAsync(this EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectedCallback callback, object state) { remoteEndPoint.ConnectAsyncpublic(localEndPoint, callback, state); }
private static SocketAsyncEventArgs CreateSocketAsyncEventArgs(EndPoint remoteEndPoint, ConnectedCallback callback, object state) { SocketAsyncEventArgs socketAsyncEventArgs = new SocketAsyncEventArgs(); socketAsyncEventArgs.UserToken = new ConnectToken { State = state, Callback = callback }; socketAsyncEventArgs.RemoteEndPoint = remoteEndPoint; socketAsyncEventArgs.Completed += SocketAsyncEventCompleted; return(socketAsyncEventArgs); }
public static void ConnectAsync(this EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectedCallback callback, object state) { var e = CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); #if NETSTANDARD if (localEndPoint != null) { var socket = new Socket(localEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { socket.ExclusiveAddressUse = false; socket.Bind(localEndPoint); } catch (Exception exc) { callback(null, state, null, exc); return; } socket.ConnectAsync(e); } else { Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, e); } #else var socket = PreferIPv4Stack() ? new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) : new Socket(SocketType.Stream, ProtocolType.Tcp); if (localEndPoint != null) { try { socket.ExclusiveAddressUse = false; socket.Bind(localEndPoint); } catch (Exception exc) { callback(null, state, null, exc); return; } } socket.ConnectAsync(e); #endif }
public static void ConnectAsync(this EndPoint remoteEndPoint, SocketClientAccessPolicyProtocol clientAccessPolicyProtocol, ConnectedCallback callback, object state) { var e = CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); e.SocketClientAccessPolicyProtocol = clientAccessPolicyProtocol; Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, e); }
public static void ConnectAsync(this EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectedCallback callback, object state) { ConnectAsyncInternal(remoteEndPoint, localEndPoint, callback, state); }
public static void ConnectAsync(this EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectedCallback callback, object state) { var e = CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); var socket = new Socket(SocketType.Stream, ProtocolType.Tcp); socket.ConnectAsync(e); }
// Token: 0x060007F4 RID: 2036 RVA: 0x0001CCD0 File Offset: 0x0001AED0 private static void ConnectAsyncpublic(this EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectedCallback callback, object state) { if (remoteEndPoint is DnsEndPoint) { DnsEndPoint dnsEndPoint = (DnsEndPoint)remoteEndPoint; IAsyncResult asyncResult = Dns.BeginGetHostAddresses(dnsEndPoint.Host, new AsyncCallback(ConnectAsyncExtension.OnGetHostAddresses), new ConnectAsyncExtension.DnsConnectState { Port = dnsEndPoint.Port, Callback = callback, State = state, LocalEndPoint = localEndPoint }); if (asyncResult.CompletedSynchronously) { ConnectAsyncExtension.OnGetHostAddresses(asyncResult); return; } } else { SocketAsyncEventArgs e = ConnectAsyncExtension.CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); Socket socket = new Socket(remoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (localEndPoint != null) { socket.ExclusiveAddressUse = false; socket.Bind(localEndPoint); } socket.ConnectAsync(e); } }
public static void ConnectAsync(this EndPoint remoteEndPoint, ConnectedCallback callback, object state, Action <Socket> OnTimeOut) { ConnectAsyncInternal(remoteEndPoint, callback, state, OnTimeOut); }
public static void ConnectAsync(this EndPoint remoteEndPoint, ConnectedCallback callback, object state) { ConnectAsyncInternal(remoteEndPoint, callback, state, null); }
static SocketAsyncEventArgs CreateSocketAsyncEventArgs(EndPoint remoteEndPoint, ConnectedCallback callback, object state) { var e = new SocketAsyncEventArgs(); e.UserToken = new ConnectToken { State = state, Callback = callback }; e.RemoteEndPoint = remoteEndPoint; e.Completed += new EventHandler <SocketAsyncEventArgs>(SocketAsyncEventCompleted); return(e); }