TcpListener & Client - sends to many bytes

  • Thread starter Thread starter Piotrekk
  • Start date Start date
P

Piotrekk

Hi
I have a problem:
when i send data:
byte[] fName =
ASCIIEncoding.ASCII.GetBytes(stringFileName);
TcpClient Client = new TcpClient();
Client.Client.Send(fName,fName.Length,SocketFlags.None);
in my case fName is 7

When i receive data on Server
byte[] buffer = new byte[256];
int size = connection.Receive(buffer);

Since size is number of received bytes, in my case it's 256
Any ideas?
PK

fName is filename. I need to send it, to allow server store file, but
until my received name is sentname+TRASH i can't create new file.
 
Hi,

TcpClient.Client is a protected property , you cannot use it.
You use TcpClient.GetStream to get the networkstream .


You should send the size of the string before the string itself, in this way
you can know apriori the amount of data you will gonna get.

cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top