C# client/server project issue

ice91785

Senior member
Oct 22, 2006
651
0
0
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!
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
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).
 

ice91785

Senior member
Oct 22, 2006
651
0
0
We are attempting to accomplish this by using TcpListener / TcpClient (our communication protocol)
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
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.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
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.
 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
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.
 

ice91785

Senior member
Oct 22, 2006
651
0
0
Dhaval....that first idea is very very close to what we are supposed to do -- can you expound upon that a bit for me?
 

BradAtWork

Senior member
Sep 5, 2005
320
0
0
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.
 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
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