|
Don't delete your message - It is rude.
Man who stand on hill with mouth open wait long time for roast duck to drop in
|
|
|
|
|
My current code works fine, but I've encountered a problem. When a client connects to the TCP server, and they type a message it works the first time, but if its entered again, it just gives you the else. So lets say I typed shutdown in the client console. It would return Command Recieved, Initiating Shutdown. But if I try it again, it just gives me the else message. Its like its not cycling through the if statement again. What kind of code should I use to solve this issue?
Here is the code:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
public class Server
{
public static void Main()
{
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 7557);
UdpClient newsock = new UdpClient(ipep);
Console.WriteLine("Waiting for a client...");
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
data = newsock.Receive(ref sender);
Console.WriteLine("Connection received from {0}", sender.ToString());
string welcome = "OpticVPS Remote Administration";
data = Encoding.ASCII.GetBytes(welcome);
newsock.Send(data, data.Length, sender);
while (true)
{
data = newsock.Receive(ref sender);
if (Encoding.ASCII.GetString(data, 0, data.Length) == "help")
{
string okay = "You can use the following commands";
Console.WriteLine("Help List Accessed By: {0}", sender.ToString());
data = Encoding.ASCII.GetBytes(okay);
newsock.Send(data, data.Length, sender);
}
else if (Encoding.ASCII.GetString(data, 0, data.Length) == "shutdown")
{
string shutdown = "Command Received, Shutting Down Now";
Console.WriteLine("Shutdown Issued - {0}", sender.ToString());
data = Encoding.ASCII.GetBytes(shutdown);
newsock.Send(data, data.Length, sender);
}
else
{
string err = "Command Not Found [End Of Line]";
Console.WriteLine("Command Error - {0}", sender.ToString());
data = Encoding.ASCII.GetBytes(err);
newsock.Send(data, data.Length, sender);
}
}
}
}
[X] 100% HTML
[ ] 100% PHP
[ ] 100% C#
|
|
|
|
|
Serpendiem wrote: What kind of code should I use to solve this issue?
Well, if you want to use TCP connections, I'd start by using a TCP[^] client and a TCP[^] server. A UdpClient isn't going to help you very much.
In response to your other question about how to close a TCP connection, you should take a look at the Close()[^] method.
|
|
|
|
|
hi
please help me
how to write a program "visual pda(push down automata) creater" with C#
cxg
|
|
|
|
|
The link in my sig has all the information you need.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
|
|
|
|
|
hi
please help me
how to write a program "visual pda(push down automata) creater" with C#
cxg
|
|
|
|
|
Well, this[^] is a good start for you, or were you expecting code?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
i want write a program to able user to create a push down automata (graphical)and see result with c#
cxg
|
|
|
|
|
Did you read the link in my sig ?
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
|
|
|
|
|
Excellent, and the link I provided is chock full of information. All you need to do now is convert the maths into code.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
hi,could u find it.plz i want this too.plz
|
|
|
|
|
Why did you ask twice ?
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
|
|
|
|
|
I have a project where I have a lot of panels on my form. It gets to be a hassel moving them front/back to edit them. Is there a way to encase the panel in a class, so I can just make it visible or invisible from class calls and not have to have it cluttering up my form during normal editing.
For example, I have a color picker panel which includes a listbox of all the color names and a picture box that I use to display the color and its name (using graphics). I can see where I could use this in several projects and don't want to have to recreate it everytime.
Gary Strunk
|
|
|
|
|
Hi,
you could create a class as in public class MyPanel : Panel {...} by creatind a code file; such Control would, after one build, be available for use by Visual Designer through the Toolbox, without residing in a separate DLL file.
or you could create a UserControl in a separate DLL file, as in public class MyPanel : UserControl {...} ; that way you can include the same DLL in other projects, and you can set its properties through Visual Designer when including it in say another Form.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi
you create a Usercontrol & insert all the panel u need. So that U can use it anywhere without recreating it.
|
|
|
|
|
I have part of my app which enumerates all video camera devices present and presents them in a drop down list. I have two Logitech web cams which have the same name, but when I click on the drop down button, only one of the cameras are listed. How do I make it so that both are displayed? If possible, how can I add a number or ideally a port number to differentiate the two instances of the web cams?
This is my code:
<pre>
public MainForm()
{
InitializeComponent();
// collect cameras list
try
{
// enumerate video devices
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count == 0)
throw new ApplicationException();
// add all devices to combo
foreach (FilterInfo device in videoDevices)
{
camerasComboLeft.Items.Add(device.Name);
camerasComboRight.Items.Add(device.Name);
}
camerasComboLeft.SelectedIndex = 0;
camerasComboRight.SelectedIndex = 0;
}
catch (ApplicationException)
{
camerasComboLeft.Items.Add("You ain't got no LEFT CAMERA son!");
camerasComboRight.Items.Add("You ain't got no RIGHT CAMERA son!");
videoDevices = null;
}
EnableConnectionControls(false);
}
.... rest of the app
</pre>
|
|
|
|
|
I guess you need to check if the name is already in the list, and if so, append a number to the name. In that instance, I am assuming you need to add the FilterInfo to the combo box, and set the DisplayMember to be the Name property, otherwise, how do you tell which is which, if not by name ?
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
|
|
|
|
|
|
What you could do is check the documentation and watch for some OpenFileDialog Properties; I bet some of them even have "Directory" in their name.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
Collin Jasnoch wrote: What documentation?
You are using OpenFileDialog and having some trouble with it, hence read its documentation. It is all in there, Google if you don't know where to find it, then read the page and learn.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
Yeah, you confused me there. If you are not using OpenFileDialog, then read up on the documentation of the code you are using or contact its provider. Chances are they intended to mimick OpenFileDialog though.
When a relative path (or just a file name) is specified, .NET (and Windows) will rely on the "Current Directory" which by default starts out to be the folder holding your EXE file; however there are many ways to change it on the go (and even at app start), so it is not a recommended way of doing things.
Better set things explicitly; also have a look at the "special folders", see Environment.GetFolderPath()
with SpecialFolder.ApplicationData and CommonApplicationData (you should use a folder hierarchy in there, based on your company name and/or product name).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
Collin Jasnoch wrote: Bitmap bmp = new Bitmap(img); will not work if img is an absolute path.
Then something is wrong with your path. Did you confuse forward and backward slashes? are you referring to a case-sensitive file system (as in UNIX/Linux)? Did you forget a slash between path and name? Did you make a mistake in escaping a backslash?
Don't go the CD way if you don't have to, fix the real problem instead.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|