Click here to Skip to main content
15,915,818 members
Home / Discussions / C#
   

C#

 
GeneralRe: Why Are Projects Organized by Class Type Instead of Business Purpose? Pin
jschell10-Aug-13 11:09
jschell10-Aug-13 11:09 
GeneralRe: Why Are Projects Organized by Class Type Instead of Business Purpose? Pin
OMVB12-Aug-13 4:38
OMVB12-Aug-13 4:38 
AnswerRe: Why Are Projects Organized by Class Type Instead of Business Purpose? Pin
Eddy Vluggen8-Aug-13 9:06
professionalEddy Vluggen8-Aug-13 9:06 
Questionscanning my network Pin
Member 101954878-Aug-13 1:37
Member 101954878-Aug-13 1:37 
AnswerRe: scanning my network Pin
Simon_Whale8-Aug-13 1:43
Simon_Whale8-Aug-13 1:43 
AnswerRe: scanning my network Pin
OriginalGriff8-Aug-13 5:24
mveOriginalGriff8-Aug-13 5:24 
GeneralRe: scanning my network Pin
Mycroft Holmes8-Aug-13 13:53
professionalMycroft Holmes8-Aug-13 13:53 
Generaldeveloping Client / Server application C#: Create code Client 2 ? Pin
hajajj 27-Aug-13 5:23
hajajj 27-Aug-13 5:23 
Hello,
I work at my school, I have a client-server application in C # with Visual Studio 2010 and I have my first client 1 that connects to server. but now I have a problem to connect a server to another client 2 in a VM (Virtual Machine: Virtual Box Windows 7).

Client 2:
* It should be the server connects to the client 2?
* The server sends a message to the client that son located in a virtual machine?
* After sent, the server received a confirmation message from client 2?

So it remains to create of client 2 code that receives a message from the server and client 2 sends a confirmation response to server and client 1?

so when I do the execution console server on my physical machine displays the following address: @ IP: 193.51.91.5:10000 & @ IP: 127.0.0.1:10000
and when I do the execution of the console server in the virtual machine (virtual box with windows 7) displays the following address: @ IP address: 192.168.56.1:10000 & @ IP: 127.0.0.1:10000
Please find attached client / server code.
Very thank you in advance and regards.

thank you

client :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using DPSBase;
using NetworkCommsDotNet;

namespace SocketProject.Client
{

class Program
{

#region [ Fields ]
private static ConnectionInfo connectionInfo = null;
private static Stopwatch _stopWatch = null;
#endregion

static void Main(string[] args)
{
string serverIP = string.Empty;
int serverPort = 0;
int loopCounter = 1;

TCPConnection serverConnection = null;
string result = string.Empty;

//Enter Params of the connection
Console.WriteLine("SVP, saisissez l’adresse IP et le port du serveur (127.0.0.1:10000) : ");
Console.WriteLine();
string serverInfo = Console.ReadLine();

serverIP = serverInfo.Split(‘:’).First();
serverPort = int.Parse(serverInfo.Split(‘:’).Last());

while (true)
{
NetworkComms.RemoveGlobalIncomingPacketHandler();
connectionInfo = new ConnectionInfo(serverIP, serverPort);
serverConnection = TCPConnection.GetConnection(connectionInfo);

//Send Message to the others clients
NetworkComms.AppendGlobalIncomingPacketHandler<string>("SendMessageToOthersClt", HandleIncomingCltMessage);
//Send Message to the serveur
NetworkComms.AppendGlobalIncomingPacketHandler<string>("CustomObjectReply", HandleIncomingSrvMessage);

Console.Write(string.Format("Entrez votre {0}{1} message : \n ", loopCounter, (loopCounter == 0) ? "er" : "eme"));
string messageToSend = Console.ReadLine();

_stopWatch = new Stopwatch();
if (messageToSend.StartsWith("SendMsg"))
{
int firstSpace = messageToSend.IndexOf(‘ ‘);
serverConnection.SendObject("SendMessageToOthersClt", messageToSend.Substring(firstSpace));
}
else
serverConnection.SendObject("RequestCustomObject", messageToSend);

Console.WriteLine();
if (Console.ReadKey(true).Key == ConsoleKey.Q) break;

loopCounter++;
}

NetworkComms.Shutdown();
}

private static void HandleIncomingSrvMessage(PacketHeader header, Connection connection, string incomingMessage)
{
string messageToShow = string.Empty;
string execTime = string.Empty;

messageToShow = "——————————————————————————-\n";
string[] res = incomingMessage.Trim().Split(‘-’);
if (res.Length > 1)
execTime = ((_stopWatch.Elapsed.Milliseconds * 1000) + int.Parse(res[0])).ToString();
else
execTime = (_stopWatch.Elapsed.Milliseconds * 1000).ToString();

switch (res[1])
{
case "LaunchVM":
messageToShow += "Virtual Box Lancée après " + execTime + "(ns)\n";
break;
case "LaunchVagrant":
messageToShow += "Vagrant Lancée après " + execTime + "(ns)\n";
break;
case "SendMsg":
messageToShow += "Le message envoyée aprés " + execTime + "(ns)\n";
break;
default:
messageToShow += "Le message ‘" + res[1] + "‘ a été reçu par le serveur après " + execTime + "(ns)\n";
break;
}
messageToShow += "——————————————————————————-\n";
Console.Write(messageToShow);
}

private static void HandleIncomingCltMessage(PacketHeader header, Connection connection, string incomingMessage)
{
TimeSpan ts = _stopWatch.Elapsed;
Console.Write(string.Format("Message reçu de la part d’un autre client : {0} \n ", incomingMessage));
}
}

}

server:
using System;
using NetworkCommsDotNet;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DPSBase;
using System.Threading;

namespace SocketProject.Server
{
class Program
{
static void Main(string[] args)
{
NetworkComms.AppendGlobalIncomingPacketHandler<string>("RequestCustomObject", (packetHeader, connection, message) =>
{
Stopwatch stopWatchLaunchVagrant = new Stopwatch();
stopWatchLaunchVagrant.Start();

string msgConsole = string.Empty;
string elapsedTime = "";

string process = "";
string workingDirectory = "";
string arg = "";

msgConsole += "—————————————————————————–\n";
msgConsole += string.Format("Message reçu de la part Client {0}, le contenu est : {1} \n", "[" + connection.ConnectionInfo.NetworkIdentifier.Value + " " + connection.ConnectionInfo.LocalEndPoint.Address.ToString() + ":" + connection.ConnectionInfo.LocalEndPoint.Port.ToString() + "]", message);

if (message == "LaunchVM")
{
process = @"VirtualBox.exe";
workingDirectory = @"C:\Program Files\Oracle\VirtualBox\";
}
else if (message == "LaunchVagrant")
{
process = "cmd.exe";
workingDirectory = @"C:\Vagrant\";
arg = "vagrant up";
}
else if (message == "LaunchVagrantDistant")
{
process = "cmd.exe";
workingDirectory = @"\\dauphine-PC\Vagrant\";
arg = "vagrant up";
}
else if (message == "test")
{
process = "devenv.exe";
workingDirectory = @"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\";
}

ProcessStartInfo psi = new ProcessStartInfo(process)
{
UseShellExecute = true,
RedirectStandardOutput = false,
RedirectStandardInput = false,
RedirectStandardError = false,
CreateNoWindow = true,
WorkingDirectory = workingDirectory
};
if (!(string.IsNullOrEmpty(arg)))
psi.Arguments = "/C " + arg;
//Process.Start(psi);
System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);

stopWatchLaunchVagrant.Stop();
elapsedTime = (p.TotalProcessorTime.TotalMilliseconds * 1000 + stopWatchLaunchVagrant.ElapsedMilliseconds * 1000).ToString();

msgConsole += "Temps d’exécution est : " + elapsedTime + "\n";
msgConsole += "—————————————————————————–\n";

Console.Write(msgConsole);

connection.SendObject("CustomObjectReply", elapsedTime + "-" + message);
});

NetworkComms.AppendGlobalIncomingPacketHandler<string>("SendMessageToOthersClt", (packetHeader, connection, message) =>
{
string msgConsole = string.Empty;
msgConsole += "—————————————————————————–\n";
msgConsole += string.Format("Le Client {0} a envoyé ce message : \" {1} \" aux autres clients \n", "[" + connection.ConnectionInfo.NetworkIdentifier.Value + " " + connection.ConnectionInfo.LocalEndPoint.Address.ToString() + ":" + connection.ConnectionInfo.LocalEndPoint.Port.ToString() + "]", message);
var allRelayConnections = (from current in NetworkComms.GetExistingConnection() where current != connection select current).ToArray();
foreach (var relayConnection in allRelayConnections)
{
try
{
relayConnection.SendObject("SendMessageToOthersClt", message);
}
catch (CommsException) { /* Catch the comms exception, ignore and continue */ }
}
msgConsole += "—————————————————————————–\n";
Console.Write(msgConsole);
});

NetworkComms.AppendGlobalConnectionEstablishHandler((connection) => { Console.Write(string.Format(" Nouveau client connecté : [IP : {0}, PORT : {1}] \n", connection.ConnectionInfo.LocalEndPoint.Address.ToString(), connection.ConnectionInfo.LocalEndPoint.Port.ToString())); });

TCPConnection.StartListening(true);
foreach (System.Net.IPEndPoint localEndPoint in TCPConnection.ExistingLocalListenEndPoints())
Console.WriteLine("Serveur demarré – Infos : {0}:{1}", localEndPoint.Address, localEndPoint.Port);
Console.WriteLine("\n Cliquez sur une touche pour fermer le serveur.");
Console.ReadKey(true);
NetworkComms.Shutdown();
}

public static string elapsedTime { get; set; }

}
}

GeneralRe: developing Client / Server application C#: Create code Client 2 ? Pin
Richard MacCutchan7-Aug-13 7:21
mveRichard MacCutchan7-Aug-13 7:21 
GeneralRe: developing Client / Server application C#: Create code Client 2 ? Pin
hajajj 27-Aug-13 12:57
hajajj 27-Aug-13 12:57 
GeneralRe: developing Client / Server application C#: Create code Client 2 ? Pin
Pete O'Hanlon7-Aug-13 13:49
mvePete O'Hanlon7-Aug-13 13:49 
GeneralRe: developing Client / Server application C#: Create code Client 2 ? Pin
hajajj 28-Aug-13 0:45
hajajj 28-Aug-13 0:45 
GeneralRe: developing Client / Server application C#: Create code Client 2 ? Pin
Pete O'Hanlon8-Aug-13 0:54
mvePete O'Hanlon8-Aug-13 0:54 
GeneralRe: developing Client / Server application C#: Create code Client 2 ? Pin
Simon_Whale8-Aug-13 1:42
Simon_Whale8-Aug-13 1:42 
GeneralRe: developing Client / Server application C#: Create code Client 2 ? Pin
hajajj 28-Aug-13 1:49
hajajj 28-Aug-13 1:49 
QuestionRe: developing Client / Server application C#: Create code Client 2 ? Pin
Eddy Vluggen8-Aug-13 9:12
professionalEddy Vluggen8-Aug-13 9:12 
GeneralRe: developing Client / Server application C#: Create code Client 2 ? Pin
Jean A Brandelero8-Aug-13 10:41
Jean A Brandelero8-Aug-13 10:41 
QuestionHow to Pop mails From Mail to biztalk then save it in database Pin
Ahmed Abdelnasser7-Aug-13 2:17
Ahmed Abdelnasser7-Aug-13 2:17 
AnswerRe: How to Pop mails From Mail to biztalk then save it in database Pin
Simon_Whale7-Aug-13 3:29
Simon_Whale7-Aug-13 3:29 
QuestionWant to create a websocket server in c# Pin
Member 101935636-Aug-13 18:50
Member 101935636-Aug-13 18:50 
AnswerRe: Want to create a websocket server in c# Pin
Abhinav S6-Aug-13 19:47
Abhinav S6-Aug-13 19:47 
QuestionConcatenating 2 columns into one (radgrid) Pin
Member 101936536-Aug-13 9:59
Member 101936536-Aug-13 9:59 
AnswerRe: Concatenating 2 columns into one (radgrid) Pin
Mycroft Holmes6-Aug-13 13:00
professionalMycroft Holmes6-Aug-13 13:00 
QuestionObjects created in a loop - definition name Pin
DSLoginYea6-Aug-13 2:02
DSLoginYea6-Aug-13 2:02 
AnswerRe: Objects created in a loop - definition name Pin
Dave Kreskowiak6-Aug-13 2:47
mveDave Kreskowiak6-Aug-13 2:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.