|
Here's a handy C program:
if (0 != strcmp("C", "C#"))
throw "You're in the wrong forum."; You might have better luck in the Visual C++[^] forum. C# is a programming language that targets the Common Language Runtime - a completely different monster from C.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi everyone,
I am a newcomer in this vast ocean. I am just a beginner, with a very basic doubt. I have a server and a client program, small basic programs written in C# and in the Microsoft Visual Editor.
My doubt is how to run this application, where in a server is up running and is waiting for the client to connect. Should they be as differnet projects? If I am having them both in the same solution or project, it says more than one entry point due to two Main() in each of them, and I cannot run two projects at the same time if I keep them two seperately.
Waiting for some help in this, as if I accomplish this I have a whole big project to be done in 2 months. So , kindly do help me.
Thank You
Sowmya Mulukutla,
Research Assistant,
Health Informatics Dept,
UAB
|
|
|
|
|
Run the other app from the Windows shell (Windows Explorer/ command prompt)
Regards
Senthil
|
|
|
|
|
Thank you for the help. But when I try to run it from the command line, nothing happens. I mean it just exits and shows the details of the C# compiler. Is there any prespecified path I need to set to execute the code?
For Eg: If ClientTCP is my project, and clientSocket.cs is my code file, then I go to the directory of the project and then do the csc ClientSocket.cs.
I am doing this from the Visual Studio.Net comman prompt only. Kindly do correct me if I am wrong.
Sorry for the trouble,
Sowmya Mulukutla,
Research Assistant,
Health Informatics Dept,
UAB
|
|
|
|
|
Yes, create 2 projects, one for the client and one for the server.
The problem you're seeing when running from command prompt is normal behavior; it runs the static void Main function, executes any code in there, then exits. If you don't want it to exit, put a Console.ReadLine() in the entry function for the console app.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
I tried that too, but no change. Other thing i observed was it is running (as individual projects) from the editor but from the command line it just exits.
I still did not figure out how to make the server and the client talk to each other.
Thank you, anyways,
Sowmya Mulukutla,
Research Assistant,
Health Informatics Dept,
UAB
|
|
|
|
|
Sorry my last mail was just a thank you in the end, anywyas just came out of habit, do not think I gave up eating ur head .
Help needed....,
Sowmya Mulukutla,
Research Assistant,
Health Informatics Dept,
UAB
|
|
|
|
|
Soumya Mulukutla wrote:
I tried that too, but no change. Other thing i observed was it is running (as individual projects) from the editor but from the command line it just exits.
Show me your server code.
Soumya Mulukutla wrote:
I still did not figure out how to make the server and the client talk to each other.
That's a seperate problem. Are you using .NET remoting? Web Services? Message Queue? DCOM? Most likely you'll need to use one of those technologies. If both your client and your server are .NET Windows or .NET Console applications, .NET remoting is probably the right choice for you.
If you need help with one of those topics, or just need general help making your client talk to your server, I suggest you start a new thread, as there's much to be said on any of the remote messaging APIs.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
I'm getting the "Tcp Channel already registered" on an application I'm working on that acts as both a server and a client to be a simple chat client. Hope someone can tell me what the issue with my code is, here's the relevant bits:
---------------------------------------------
//Server
TcpChannel channel = new TcpChannel(8002);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(Hello), "Hi", WellKnownObjectMode.SingleCall);
//Rest of code here
// Client (on button click)
string ipaddr = textBox2.Text;
string port = textBox3.Text;
TcpChannel chan = new TcpChannel(8001);
ChannelServices.RegisterChannel(chan);
Hello obj = (Hello)Activator.GetObject(
typeof(Hello), "tcp://" + ipaddr + ":" + port + "/Hi");
---------------------------------------------------
Thanks in advance,
Matt
|
|
|
|
|
Maybe the process didn't exit properly and is still in memory? Have a look at the running processes in Task Manager.
Regards
Senthil
|
|
|
|
|
Thanks for the reply I've tested this app on the laptop and desktop, and same result on both. All times, the program exits correctly
Anymore ideas?
Many thanks,
Matt
|
|
|
|
|
Yes. The problem is that the application is trying to register a channel on the same port multiple times. That isn't allowed; what you need is to register each channel you have on a different port.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
So simply putting the different port numbers as i have (8001 and 8002) isn't enough?
|
|
|
|
|
There has to be another place in your code that is registering 8001 or 8002. Set debug breakpoints or output some text letting you know when a channel is about to be registered. The only time this message would occur is if a channel has already been registered on that port.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
When you think your program has exited clean, start a command prompt an type:
netstat -a
Look in the output for a "TCP computername:yourportnum..."
If you find an entry for one of your ports, then something is still running.
|
|
|
|
|
Is there any method to append to a string, here's what I'm doing:
<br />
string selectString = "SELECT * FROM table_name WHERE ";<br />
<br />
if(programName.Text != null)<br />
{<br />
}<br />
Any ideas?
|
|
|
|
|
Have you looked at the StringBuilder class?
|
|
|
|
|
If you are trying to append the string in a loop or trying to do a lot of appending, use the StringBuilder class. Otherwise just use
<br />
selectString += "Whatever text to be appended";<br />
Regards
Senthil
|
|
|
|
|
Apart from all that - I would never, never build SQL like this. To be honest, I'd never build SQL at all in my middle tier, I'd put it all in stored procedures.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
|
I went ahead and used the += syntax for now as I'm reading up on stored procedures as I write this (pretty talented eh? :-P)
thanks for the advice all.
PS - is there an informal rule to go by as to when to use stored procedures or to use StringBuilder?
|
|
|
|
|
why can't u try to insert
by writing:
this.yourText.insert(); // and these parameters have the starting index which will be your string's textLenght-1 and your additional string
ByMindOnlyYouCanDoIt
|
|
|
|
|
never, Never, NEver, NEVer, NEVEr, NEVER(!!) use string concatenation to build SQL statements. All your doing is teaching someone how to get themselves fired from a developer job. Instead, teach them the best way: stored procedures and parameterized queries.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
When I use System.Diagnostics.Process to launch a console app such as NAnt, the process hangs whenever the memory it uses exceeds some arbitrary amount.
In the NAnt example, this command line will execute to completion without errors: "NAnt.exe -buildfile:Some.Build -logfile:Some.log"
But this command line will hang and NAnt will not compile anything:
"NAnt.exe -verbose -buildfile:Some.Build -logfile:Some.log"
<br />
System.Diagnostics.ProcessStartInfo _StartInfo = new System.Diagnostics.ProcessStartInfo(command, commandParameters);<br />
System.Diagnostics.Process _Process = new System.Diagnostics.Process();<br />
_StartInfo.WorkingDirectory = workingDirectory;<br />
_StartInfo.RedirectStandardOutput = true;<br />
_StartInfo.UseShellExecute = false;<br />
_Process.StartInfo = _StartInfo;<br />
_Process.Start();<br />
TIA for any help.
|
|
|
|
|