473,246 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

Windows sockets (tcpclient) problem.

hi..
im writing an application that uses tcpclient/tcplistener to send file
via network, what im doing is dividing the file into small parts each
part equals the buffer size (8192) and send the parts sequentialy.
the problem is :
the listener is detecting a stream to be read once every two times the
sender sends a stream.
I triend to fix it by sending one byte {0} before each send function
and it worked because the listener ignores the first send (which is the
0 byte) then detects the next send which is the acutaul data, but i
realized that the 0 byte is still in the buffer so its attached the
next stream read.
any help? any idea is appreciated .. thank you in advance.

Nov 23 '05 #1
1 1508
hi,

"Inspired" <mu***********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
hi..
im writing an application that uses tcpclient/tcplistener to send file
via network, what im doing is dividing the file into small parts each
part equals the buffer size (8192) and send the parts sequentialy.
the problem is :
the listener is detecting a stream to be read once every two times the
sender sends a stream.
I triend to fix it by sending one byte {0} before each send function
and it worked because the listener ignores the first send (which is the
0 byte) then detects the next send which is the acutaul data, but i
realized that the 0 byte is still in the buffer so its attached the
next stream read.
any help? any idea is appreciated .. thank you in advance.
TCP is a byte-stream protocol not a message or package stream, if you send a
buffer it can be split or joined.

If you want a packet stream then you have to build your protocol on top of
it, either by using:
- delimiter between packets
- prefixing each variable packet with the packet length
- using fixed size packets

You are already using fixed size packets, but the end packet of the file may
have a different size, at the least you will need to send the length of the
file before transmitting the file : (pseudocode)

Do While( receivedBytes < fileSize )
int i = receive ( 4000 bytes)
' nothing garantees we have received 4000 bytes
' that's why i is used
receivedBytes+= i
add i received bytes to byte queue
If ( byte queue >= 8192 )
process first 8192 from byte queue
remove first 8192 from byte queue
End If
End
process last packet, which could be smaller then 8192

Also note that for file transfer it may not be necesairy to receive them in
blocks (just write the bytes as they come in), except if you want to do a
checksum or something on a block basis.

HTH,
Greetings

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for...
0
by: Torsten Brasch | last post by:
Hi All and Happy New Year ;) I have a very strange problem with System.Net.Sockets.TcpClient(). For some reason, the number of bytes I can receive is limited to 5460 bytes. I made sure that the...
4
by: Sueffel | last post by:
Boy, someday I may get good at this stuff! Until then, I have a "TCP server" that accepts multiple connections. That all works wonderfully! YEAH!!!! I have a TCPClient that is the client...
4
by: BadOmen | last post by:
Hi, What is the different between 'System.Net.Sockets.Socket' and 'System.Net.Sockets.TcpClient'? When do I use System.Net.Sockets.TcpClient and System.Net.Sockets.Socket?? Yours, Jonas
0
by: Tim Wagaman | last post by:
I an having issuses with a loop I am running to keep checking for messages coming across our line. The goal: Listen for messages on port 5001 and print the messages into a text file. The port...
9
by: TulasiKumar | last post by:
Hi all, What is my requirement is i want to get the TCPIP data from TCP Port.I had written the code in c#.Net.What i had written the code is pasted below.what i written the code is correct or...
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
2
by: jgbid | last post by:
Hi, I'm trying to build an IP Scanner inc c# for a specific port (80) and for specific IP Ranges. For example 24.36.148.1 to 24.36.148.255 My first step was to use TcpClient, but there are...
1
by: larspeter | last post by:
Hi all. I have a problem with TcpClient ... I am conneting to a server with TcpClient and returning the answer through a webservice. It actully all works fine. BUT if I make a lot of...
4
by: keithseah | last post by:
Hi all, i've been having this problem and its kiiling me! i'm a newbie at this so i hope someone would be able to help me. picture link:...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.