protected override void Init() { base.Init(); client = new ClientPeer(); client.Connect("127.0.0.1", 6666); DontDestroyOnLoad(gameObject); }
void Awake() { instance = this; controllers = new Dictionary <byte, ControllerBase>(); peer = new ClientPeer(this); peer.Connect("192.168.1.20", "26680"); }
static void Main(string[] args) { IPEndPoint superPeerEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8090); int port = 8091; ServerPeer server = new ServerPeer(superPeerEndPoint, port); server.Run(); ClientPeer client = new ClientPeer(superPeerEndPoint); client.Run(); //used Task.Factory.StartNew(() and sleep to simulate that this tasks are performed on different applications/machines Task.Factory.StartNew(() => server.AllowConnection(client.GetPeerAddress())); Thread.Sleep(3000); Task.Factory.StartNew(() => client.Connect(server.GetPeerAddress())); Thread.Sleep(3000); server.Send(new byte[] { 1, 2, 3, 4, 5 }); Console.WriteLine(client.Read()); client.Close(); Thread.Sleep(1000); server.Close(); Thread.Sleep(60000); }
private void Awake() { Instance = this; DontDestroyOnLoad(gameObject); // 切换场景后也不能让他销毁掉 client = new ClientPeer(); client.Connect("127.0.0.1", 6666); }
private void Awake() { Instance = this; DontDestroyOnLoad(gameObject); client = new ClientPeer(); client.Connect("39.98.40.96", 6666); }
public ClientEngine() { controllers = new Dictionary <byte, ControllerBase>(); instance = this; peer = new ClientPeer(this); peer.Connect("192.168.1.20", "26680"); RegisterAllController(); }
private void Awake() { Instance = this; //连接以后不摧毁连接体,这样进入下一个场景还能保持网络连接 DontDestroyOnLoad(gameObject); client = new ClientPeer(); client.Connect("127.0.0.1", 6666); }
private void Awake() { Instance = this; DontDestroyOnLoad(gameObject); client = new ClientPeer(); client.Connect("127.0.0.1", 8080); }
private static Iso8583Message GetSinkNodeResponse(ClientPeer sinkNodePeer, Iso8583Message isoMessage) { sinkNodePeer.Connect(); int tries = 10; while (!sinkNodePeer.IsConnected && tries > 0) { Console.WriteLine("Could not connect to sink node. Retrying in 5 seconds"); tries--; sinkNodePeer.Connect(); Thread.Sleep(5000); } if (tries <= 0 && !sinkNodePeer.IsConnected) { Console.WriteLine("Reconnection attempts failed. Could not connect to sink"); if (isoMessage.Fields.Contains(IsoMessageFieldDefinitions.RESPONSE_CODE)) { isoMessage.Fields[IsoMessageFieldDefinitions.RESPONSE_CODE].Value = IsoMessageFieldDefinitions.ResponseCodes.ISSUER_SWITCH_INOPERATIVE; } else { isoMessage.Fields.Add(IsoMessageFieldDefinitions.RESPONSE_CODE, IsoMessageFieldDefinitions.ResponseCodes.ISSUER_SWITCH_INOPERATIVE); } return(isoMessage); } var request = new PeerRequest(sinkNodePeer, isoMessage); request.Send(); request.WaitResponse(50000); var sinkNodeReponse = request.ResponseMessage as Iso8583Message; request.Peer.Close(); return(sinkNodeReponse); }
public static void ClientPeer(SinkNode sinkNodeToConnect, List <ClientPeer> clientPeers) //join conn { ClientPeer client = new ClientPeer(sinkNodeToConnect.Id.ToString(), new TwoBytesNboHeaderChannel(new Iso8583Ascii1987BinaryBitmapMessageFormatter(), sinkNodeToConnect.HostName, Convert.ToInt32(sinkNodeToConnect.Port)), new BasicMessagesIdentifier(11, 41)); client.RequestDone += new PeerRequestDoneEventHandler(Client_RequestDone); client.RequestCancelled += new PeerRequestCancelledEventHandler(Client_RequestCancelled); client.Connected += client_Connected; client.Receive += new PeerReceiveEventHandler(Client_Receive); clientPeers.Add(client); client.Connect(); Console.WriteLine("Waiting for connection.."); }
public static void SinkPeers() { IList <SinkNode> sinkNodes = new GenericService <SinkNode>().FilterBy(x => x.Status == true); foreach (var sinkNode in sinkNodes) { Console.Write("Initializing ClientPerrs peers\n"); ClientPeer client = new ClientPeer(sinkNode.Id.ToString(), new TwoBytesNboHeaderChannel(new Iso8583Ascii1987BinaryBitmapMessageFormatter(), sinkNode.IPAdress, sinkNode.Port), new BasicMessagesIdentifier(11, 41)); client.RequestDone += new PeerRequestDoneEventHandler(Client_RequestDone); // Log(string.Format("Request Done")); client.RequestCancelled += new PeerRequestCancelledEventHandler(Client_RequestCancelled); //ListOfClient.Add(client); client.Connect(); } }
public void Connect(string hostname, int port) { try { peer = new ClientPeer(this); if (!peer.Connect(hostname, port)) { OnConnectResponse(false); } } catch (Exception ex) { OnConnectResponse(false); DebugReturn(DebugLevel.Error, ex.Message); DebugReturn(DebugLevel.Error, ex.StackTrace); } }
private void Start() { client.Connect(); }
public void Connected() { client.Connect(); }
private Iso8583Message ToFEP(Iso8583Message msgToSend, SinkNode sinkNode, out bool needReversal) { Message response = null; string responseMsg = string.Empty; needReversal = false; try { if (msgToSend == null) { Logger.Log("Iso message is null."); return(SetReponseMessage(msgToSend, "20")); //Invalid response } if (sinkNode == null) { Logger.Log("Sink node is null."); return(SetReponseMessage(msgToSend, "91")); //Issuer inoperative } int maxNoRetries = 3; int serverTimeout = 60000; sinkNode.IsActive = true; ClientPeer _clientPeer = new ClientPeer(sinkNode.Name, new TwoBytesNboHeaderChannel( new Iso8583Ascii1987BinaryBitmapMessageFormatter(), sinkNode.IPAddress, Convert.ToInt16(sinkNode.Port)), new Trx.Messaging.BasicMessagesIdentifier(11)); _clientPeer.Connect(); Thread.Sleep(1800); int retries = 0; while (retries < maxNoRetries) { if (_clientPeer.IsConnected) { break; } else { _clientPeer.Close(); retries++; _clientPeer.Connect(); } Thread.Sleep(2000); } PeerRequest request = null; if (_clientPeer.IsConnected) { request = new PeerRequest(_clientPeer, msgToSend); request.Send(); request.WaitResponse(serverTimeout); //request.MarkAsExpired(); //uncomment to test timeout if (request.Expired) { Logger.Log("Connection timeout."); needReversal = true; return(SetReponseMessage(msgToSend, "68")); //Response received too late } if (request != null) { response = request.ResponseMessage; //ResponseMessage = GetResponseMesage(response as Iso8583Message); } return(response as Iso8583Message); } else { Console.WriteLine("\n Could not connect to the Sink Node.."); Console.BackgroundColor = ConsoleColor.Red; Logger.Log("\n Could not connect to the Sink Node."); return(SetReponseMessage(msgToSend, "91")); } } catch (Exception ex) { Logger.Log("ERROR: " + ex.Message); return(SetReponseMessage(msgToSend, "06")); //Error } }
private void Awake() { ClientPeer client = new ClientPeer(); client.Connect("127.0.0.1", 6666); }
public async Task Connect(string address, ushort port) { _clientPeer.Connect(address, port); await WaitFor <ConnectedEvent>(); }
private Iso8583Message ToFEP(Iso8583Message msgToSend, SinkNode sinkNode, out bool needReversal) { Message response = null; string responseMsg = string.Empty; needReversal = false; try { if (msgToSend == null) { Logger.Log("Iso message is null."); return SetReponseMessage(msgToSend, "20"); //Invalid response } if (sinkNode == null) { Logger.Log("Sink node is null."); return SetReponseMessage(msgToSend, "91"); //Issuer inoperative } int maxNoRetries = 3; int serverTimeout = 60000; sinkNode.IsActive = true; ClientPeer _clientPeer = new ClientPeer(sinkNode.Name, new TwoBytesNboHeaderChannel( new Iso8583Ascii1987BinaryBitmapMessageFormatter(), sinkNode.IPAddress, Convert.ToInt16(sinkNode.Port)), new Trx.Messaging.BasicMessagesIdentifier(11)); _clientPeer.Connect(); Thread.Sleep(1800); int retries = 0; while (retries < maxNoRetries) { if (_clientPeer.IsConnected) { break; } else { _clientPeer.Close(); retries++; _clientPeer.Connect(); } Thread.Sleep(2000); } PeerRequest request = null; if (_clientPeer.IsConnected) { request = new PeerRequest(_clientPeer, msgToSend); request.Send(); request.WaitResponse(serverTimeout); //request.MarkAsExpired(); //uncomment to test timeout if (request.Expired) { Logger.Log("Connection timeout."); needReversal = true; return SetReponseMessage(msgToSend, "68"); //Response received too late } if (request != null) { response = request.ResponseMessage; //ResponseMessage = GetResponseMesage(response as Iso8583Message); } return response as Iso8583Message; } else { Console.WriteLine("\n Could not connect to the Sink Node.."); Console.BackgroundColor = ConsoleColor.Red; Logger.Log("\n Could not connect to the Sink Node."); return SetReponseMessage(msgToSend, "91"); } } catch (Exception ex) { Logger.Log("ERROR: " + ex.Message); return SetReponseMessage(msgToSend, "06"); //Error } }