public void CreateLobbyAndAddOnePlayerAndSetTwiceLobby() { bool hasThrown = false; string lobbyName = "toto"; Connection.StartListening(ConnectionType.TCP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)); IPEndPoint lastServerIPEndPoint = (System.Net.IPEndPoint)Connection.ExistingLocalListenEndPoints(ConnectionType.TCP)[0]; ConnectionInfo targetServerConnectionInfo = new ConnectionInfo(lastServerIPEndPoint.Address.MapToIPv4().ToString(), lastServerIPEndPoint.Port); try { LobbyManager.AddLobby(lobbyName); TCPConnection connection = TCPConnection.GetConnection(targetServerConnectionInfo); LobbyManager.GetLobby(lobbyName).AddPlayer(connection); LobbyManager.GetLobby(lobbyName).AddPlayer(connection); } catch (Exception) { hasThrown = true; } finally { LobbyManager.DeleteLobby(lobbyName); } NetworkComms.Shutdown(); Assert.AreEqual(true, hasThrown); }
public void Connect() { //Trigger the method PrintIncomingMessage when a packet of type 'Network' is received NetworkComms.AppendGlobalIncomingPacketHandler <Network>("Network", PrintIncomingMessage); NetworkComms.AppendGlobalConnectionEstablishHandler(OnConnectionEstablished); NetworkComms.AppendGlobalConnectionCloseHandler(OnConnectionClosed); Thread.Sleep(net.SLEEP); //Start listening for incoming connections Connection.StartListening(ConnectionType.TCP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 2222)); //Print out the IPs and ports we are now listening on Console.WriteLine("Server listening for TCP connection on:"); foreach (System.Net.IPEndPoint localEndPoint in Connection.ExistingLocalListenEndPoints(ConnectionType.TCP)) { Console.WriteLine("{0}:{1}", localEndPoint.Address, localEndPoint.Port); } Console.WriteLine("\ntype quit' to close server."); while (Console.ReadLine() != "quit") { ; } //We have used NetworkComms so we should ensure that we correctly call shutdown NetworkComms.Shutdown(); }
private void Form1_Load(object sender, EventArgs e) { //Trigger the method PrintIncomingMessage when a packet of type 'Message' is received //We expect the incoming object to be a string which we state explicitly by using <string> NetworkComms.AppendGlobalIncomingPacketHandler <string>("InitClient", this.InitClient); //Trigger the method PrintIncomingMessage when a packet of type 'Message' is received //We expect the incoming object to be a string which we state explicitly by using <string> NetworkComms.AppendGlobalIncomingPacketHandler <string>("Message", this.PrintIncomingMessage); //Start listening for incoming connections Connection.StartListening(ConnectionType.TCP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, serverPortStatic)); //Print out the IPs and ports we are now listening on richTextBox1.AppendText("Server listening for TCP connection on:"); richTextBox1.AppendText("\n"); foreach (System.Net.IPEndPoint localEndPoint in Connection.ExistingLocalListenEndPoints(ConnectionType.TCP)) { richTextBox1.AppendText(String.Format("{0}:{1}", localEndPoint.Address, localEndPoint.Port)); richTextBox1.AppendText("\n"); } //Let the user close the server richTextBox1.AppendText("\nPress ShutDown to close server."); richTextBox1.AppendText("\n"); //ClientForm a = new ClientForm("as", "asd"); //We have used NetworkComms so we should ensure that we correctly call shutdown }
static void Main(string[] args) { //These methods will be triggered when an incoming messgae of that specified title is received //the type of receipt is explicitly stated NetworkComms.AppendGlobalIncomingPacketHandler <int>("Connect", GetConnect); NetworkComms.AppendGlobalIncomingPacketHandler <int>("Mode", GetMode); NetworkComms.AppendGlobalIncomingPacketHandler <int>("numColumns", GetColumns); NetworkComms.AppendGlobalIncomingPacketHandler <int>("numAttempts", GetAttempts); NetworkComms.AppendGlobalIncomingPacketHandler <string[]>("secretCombination", GetsecretCombination); NetworkComms.AppendGlobalIncomingPacketHandler <string[]>("guess", HandleGuess); //Start listening for incoming connections Connection.StartListening(ConnectionType.TCP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)); //Print out the IPs and ports we are now listening on Console.WriteLine("Server listening for TCP connection on:"); foreach (System.Net.IPEndPoint localEndPoint in Connection.ExistingLocalListenEndPoints(ConnectionType.TCP)) { Console.WriteLine("{0}:{1}", localEndPoint.Address, localEndPoint.Port); } //Let the user close the server Console.WriteLine("\nPress any key to close server."); Console.ReadKey(true); //I have used NetworkComms so we should ensure that we correctly call shutdown NetworkComms.Shutdown(); }
/** * This function display all the IP EndPoints. */ public void ListEndPoints() { Server.Instance.PrintOnDebug("Server listening for TCP connection on :"); foreach (System.Net.IPEndPoint localEndPoint in Connection.ExistingLocalListenEndPoints(ConnectionType.TCP)) { Console.WriteLine("\t{0}:{1}", localEndPoint.Address, localEndPoint.Port); } }
public void StartListening() { Connection.StartListening(ConnectionType.TCP, adress); NetworkComms.AppendGlobalIncomingPacketHandler <byte[]>("PartialFileData", IncomingPartialFileData); NetworkComms.AppendGlobalIncomingPacketHandler <SendInfo>("PartialFileDataInfo", IncomingPartialFileDataInfo); NetworkComms.AppendGlobalIncomingPacketHandler <string>("Message", ReadIncommingCommand); Console.WriteLine("Server listening for TCP connection on:"); foreach (System.Net.IPEndPoint localEndPoint in Connection.ExistingLocalListenEndPoints(ConnectionType.TCP)) { Console.WriteLine("{0}:{1}", localEndPoint.Address, localEndPoint.Port); } }
public void StartServer() { System.Net.IPEndPoint adress = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), 8080); Connection.StartListening(ConnectionType.TCP, adress); ConfigureServer(); Console.WriteLine("Server listening for TCP connection on:"); foreach (System.Net.IPEndPoint localEndPoint in Connection.ExistingLocalListenEndPoints(ConnectionType.TCP)) { Console.WriteLine("{0}:{1}", localEndPoint.Address, localEndPoint.Port); } }
public Server() { // Handlers NetworkComms.AppendGlobalIncomingPacketHandler <string>("Name", NewCientConnection); NetworkComms.AppendGlobalIncomingPacketHandler <int>("Ready", ReadyToPlay); NetworkComms.AppendGlobalIncomingPacketHandler <int>("disconnected", DisconnectionClient); NetworkComms.AppendGlobalIncomingPacketHandler <string>("Shot", ShotClient); // Open connection Connection.StartListening(ConnectionType.UDP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)); Console.WriteLine("Server listening for UDP connection on:"); foreach (System.Net.IPEndPoint localEndPoint in Connection.ExistingLocalListenEndPoints(ConnectionType.UDP)) { Console.WriteLine("{0}:{1}", localEndPoint.Address, localEndPoint.Port); } }
public static void Main() { //Trigger the method PrintIncomingMessage when a packet of type 'Message' is received //We expect the incoming object to be a string which we state explicitly by using <string> NetworkComms.AppendGlobalIncomingPacketHandler <string>("Message", ProcessReceivedMessage); //Start listening for incoming connections Connection.StartListening(ConnectionType.TCP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 8083)); //Print out the IPs and ports we are now listening on Console.WriteLine("Server listening for TCP connection on:"); foreach (System.Net.IPEndPoint localEndPoint in Connection.ExistingLocalListenEndPoints(ConnectionType.TCP)) { Console.WriteLine("{0}:{1}", localEndPoint.Address, localEndPoint.Port); } //Let the user close the server Console.WriteLine("\nPress any key to close server."); Console.ReadKey(true); //We have used NetworkComms so we should ensure that we correctly call shutdown NetworkComms.Shutdown(); }
static void Main(string[] args) { NetworkComms.AppendGlobalIncomingPacketHandler <MessageObject>("Message", Connected); Connection.StartListening(ConnectionType.TCP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)); Console.WriteLine("Server listening for TCP connection on:"); foreach (System.Net.IPEndPoint localEndPoint in Connection.ExistingLocalListenEndPoints(ConnectionType.TCP)) { Console.WriteLine("{0}:{1}", localEndPoint.Address, localEndPoint.Port); } createDeck(); /* * int i = 0; * while (i < 52) * { * Console.WriteLine("[" + deck[i].rank + " of " + deck[i].sign + "]"); * i++; * } * i = 0; * Console.WriteLine("\n////////////////////////////////\n"); */ Shuffle(); /* * while (i < 52) * { * Console.WriteLine("[" + deck[i].rank + " of " + deck[i].sign + "]"); * i++; * } */ bool cond = true; while (end != true) { if (play == true) { play = false; MessageObject msg = new MessageObject("Bienvenue", "Bienvenue"); if (nturn >= 52) { msg.action = "End"; if (point1 > point2) { msg.action = "End"; msg.message = "Vous avez gagné !"; player1.SendObject("Message", msg); msg.action = "End"; msg.message = "Vous avez perdu..."; player2.SendObject("Message", msg); } else if (point2 > point1) { msg.action = "End"; msg.message = "Vous avez gagné !"; player2.SendObject("Message", msg); msg.action = "End"; msg.message = "Vous avez perdu..."; player1.SendObject("Message", msg); } else if (point1 == point2) { msg.action = "End"; msg.message = "Egalité !"; player1.SendObject("Message", msg); player2.SendObject("Message", msg); } end = true; } else { if (nplay == 1) { msg.action = "You"; if (nturn != 0) { msg.message = "L'adversaire a joué la carte : " + cardPlayed.card2 + "\nA vous de poser une carte..."; } else { msg.message = "A vous de poser une carte..."; } player1.SendObject("Message", msg); msg.action = "Other"; msg.message = "L'adversaire pose une carte..."; player2.SendObject("Message", msg); nturn++; } else { msg.action = "You"; msg.message = "L'adversaire a joué la carte : " + cardPlayed.card1 + "\nA vous de poser une carte..."; player2.SendObject("Message", msg); msg.action = "Other"; msg.message = "L'adversaire pose une carte..."; player1.SendObject("Message", msg); nturn++; while (wait != true) { i++; } if (firstPlay == true && secPlay == true) { check_better(); } } } } if (nbPlayers == 2) { if (cond == true) { cond = false; MessageObject msg = new MessageObject("Bienvenue", "Bienvenue"); player1.SendObject("Message", msg); player2.SendObject("Message", msg); msg.action = "Card"; int i = 0; while (i < 26) { msg.message = "[" + deck[i].rank + " of " + deck[i].sign + "]"; player1.SendObject("Message", msg); i++; } while (i < 52) { msg.message = "[" + deck[i].rank + " of " + deck[i].sign + "]"; player2.SendObject("Message", msg); i++; } //Console.WriteLine("test\n"); msg.action = "Message"; msg.message = "Le jeu peut commencer."; player1.SendObject("Message", msg); player2.SendObject("Message", msg); play = true; //end = true; } } } Console.WriteLine("\nPress any key to close server."); Console.ReadKey(true); NetworkComms.Shutdown(); }