• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C# client/server project issue

ice91785

Senior member
So basically it is as the title says: a "client-server" type program. Basically the objective is that a client has to query a server (actually just two projects that are "talking" on port 8888 right now...) about some quotes that the server has stored in an array.

The client has three options to input in a text box: '1' displays a random quote, '2' displays all quotes present and '3' displays a command list (what I am typing right now).

I am pretty new to C# so I am having trouble grasping how a string can effectively be read in the server project FROM the client project. (I will parse to an integer after the server reads the "text" value)

Forgive me if I am missing anything important -- I will be happy to provide you with anything you'd need

THANKS!
 
You've lost me. The server "project" results in a running server process. The client project produces a client process. If you enter data into a textbox in the client process and want to get it to the server process you need some communications protocol. You could use HTTP and POST the strings as part of a form, or querystring (GET), or you could use some other protocol (named pipes, memory mapped files, remoting, whatever).
 
You still need a method for encoding/decoding the data on both ends of the connection which is what Markbnj was suggesting. TCP is just a transport mechanism, you still need to feed the connection your data. I've only got experience using web services in C# so I don't know much about named pipes or the others that Markbnj suggested but I would suggest you start googling around on the few protocols Markbnj suggested.
 
Both will have to open a socket for the related post.

One hangs a read out, the other writes the data string.

the Reader will get an interrupt andthe extract the data string.
 
If you're simply using strings, you can convert the strings to their corresponding byte[] representation and push/pull data down/from the TCP socket.

If you need to exchange actual objects, you'll need to use either Remoting or Web Services (Web Services are limited in the sense that they can't interpret complex objects precisely).

If you're using .NET 3.5, look up named pipes (these can be used if your client and server are hosted on the same machine). But my guess is this won't be the case, because it is a client/server setup to start off with.

CodeProject has tons of examples on TcpClient/TcpListener and Remoting.
 
Dhaval....that first idea is very very close to what we are supposed to do -- can you expound upon that a bit for me?
 
Originally posted by: ice91785
Dhaval....that first idea is very very close to what we are supposed to do -- can you expound upon that a bit for me?

string myString = "Convert this here string to a byte array.";
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] myBytes = encoding.GetBytes(myString);

Sorry, i'm a VB.Net guy. But I think this is what you're after.
 
Originally posted by: BradAtWork
Originally posted by: ice91785
Dhaval....that first idea is very very close to what we are supposed to do -- can you expound upon that a bit for me?

string myString = "Convert this here string to a byte array.";
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] myBytes = encoding.GetBytes(myString);

Sorry, i'm a VB.Net guy. But I think this is what you're after.

I have had issues with using a specific Encoding across different OSs- When you access System.Text.Encoding, you'll get options for UTF, UTF16, and so on. Use the "Default" Encoding... it binds to native OS encoding, and minimizes interoperability issues.

Also, you can extract a string from a byte[] in a similar manner - use Encoding.GetString().

http://msdn.microsoft.com/en-us/library/ds4kkd55.aspx
http://msdn.microsoft.com/en-us/library/744y86tc.aspx
http://msdn.microsoft.com/en-u...sockets.tcpclient.aspx
 
Back
Top