Question:
How do i run this in the visual studio console window ?
2010-07-03 14:25:53 UTC
// Use Visual Studio console window for compiling and running this application
// To compile, run "csc AreaClient.cs"
// To run, first run "AreaServer" according to the instruction in file "AreaServer.cs"
// in another console window, then run "AreaClient"
using System;
using System.Net.Sockets;
using System.Net;
using System.IO;

public class AreaClient {
public static void Main(String[] args) {
String serverURL = "localhost";
if (args.Length > 0)
serverURL = args[0]; // Take server URL from the command-line argument
try {
// Creates a socket connecting to the server's IP address and port number.
TcpClient connectToServer = new TcpClient();
connectToServer.Connect(serverURL, 8000);
// Get NetworkStream associated with TcpClient
NetworkStream stream = connectToServer.GetStream();
// Create objects or writing and reading across stream
BinaryWriter writer = new BinaryWriter(stream); // For writing to server
BinaryReader reader = new BinaryReader(stream); // for reading from server
// Continuously send radius and receive area from the server
while (true) {
// Read a radius from an input dialog
Console.Write("Please enter a radius: ");
String s = Console.ReadLine();
double radius;
try {
radius = Double.Parse(s);
}
catch (Exception) {
Console.WriteLine("Input parsing error");
break;
}

// Send the radius to the server
writer.Write(radius);
// Get area from the server
double area = reader.ReadDouble();

// Print area on the console
Console.WriteLine("Area received from the server is " + area);
}
}
catch (IOException e) {
Console.WriteLine(e.Message);
}
}
}
Three answers:
2010-07-03 14:48:44 UTC
First, you should create a new project (File => New Project...). In the window that just opened, choose the "Console Application" option and if asked - choose C# as your programming language.

Now simply copy and paste the code you posted above and run the solution by pressing Ctrl+F5 or by going to Debug => Start Without Debugging.
Ratchetr
2010-07-03 15:20:09 UTC
To compiler from command line rather than inside Visual Studio:



Look in All Programs for Microsoft Visual Studio.

Look for a subfolder under there named Visual Studio Tools.

In there, there should be a shortcut for Visual Studio Command Prompt.



Run that, switch to the folder where your source code is located.

Then compile:

csc AreaClient.cs



That should build the exe, which you can now run.
2016-03-03 11:14:19 UTC
i have no idea


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...