C#: Send message to another socket from current active socket -


The server listener starts accepting connections from all IPs:

  While (true) {commandmanager cm = new commandmanager (S. accept ()); } Public Commands Manager (Socket Client Socket) {this.socket = clientSocket; This.networkStream = New NetworkStream (this.socket); This.bwReceiver = new backgroundwork (); This.bwReceiver.DoWork + = New DoWorkEventHandler (StartReceive); This.bwReceiver.RunWorkerAsync (); } Private Wide Start Receive (Object Sender, Duplicate Event ARGS E) {while (this.socket.connected) {string s = dataStr.Substring (10); Command c = JsonConvert.DeserializeObject & lt; Command & gt; (s); Command hindler Handley Commands (C, Client IP, this .cat); This.networkStream.Flush (); }}  

command handler depends on the command, and when the command is received (from Corona SDK app) everything works great Problems occur When I need to send back the message after receiving a message. First of all, if a player logs then I save the communication information in the communication class that saves information about the socket:

  player.player p = new Player.player (cmd .player id); P. Communication = New Client Communications (Client Socket);  

However, if the command is "updated" then I also need to return the table information to all active players and this is the situation where the problem occurs:

 < Code> if (cmd.Cmd = Command.UpdateTable) {// Update // send back updates to players command c = new command (); C. CMD = Order Reservable; C.Tables = new list & lt; Table.Table & gt; (); Table Table T = tablet. The Manager. Returning (CMD. Table.TableID); C.Tables.Add (t); String command = JsonConvert.SerializeObject (c); Command = command + environment new line; Forrest (seat seat in T. T. Players) {try.CLientCommunication com = Player.PlayerManager.GetCommunication (seat.Player.PlayerID); Socket Client = com.ReturnSocket (); Client.Send (Encoding.ASCII.GetBytes (order)); } Hold (exception e) {System.Windows.Forms.MessageBox.Show (e.ToString ()); }}}  

I have verified that port and IP are correct in client.Send () but only one message gets me back to the original sender (I.e. the message sent to the player sent to the message, but the other player does not receive anything from client.Send () ).


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -