473,394 Members | 1,812 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,394 software developers and data experts.

TCP Socket - text size limit

I am trying to send strings over a simple TCP Socket connection but it will not send more than about 7 kBytes.
I am not using the TCPListener / TCPClient but the Socket class, the socket parameters being NetworkFamily.Internetwork, Protocol.Tcp, and Stream as a socket type.

To send data, I am using the Socket.Send() member.
The server accepts the connection synchronously and creates a new socket and it all works perfectly and as long as I am having small strings it is not a problem. The receive buffer I tried to set to varying sizes with no change.

Do I need to get more complicated - do I need to use streams and all kinds of things? I have seen samples which just use Send() as I am but it's not working for me. I am using the .NET Framework 2.0 in C#.

Regards

Peter
Mar 10 '08 #1
5 2006
Plater
7,872 Expert 4TB
Hmm I have not had trouble with length before. I've sent up to about a meg with my own stuff.
What are you using for code exactly?
Mar 10 '08 #2
Thanks for the reply.

Below is the relevant code snippet. It is just a test sample but works okay to connect and get text sent, except for the strange limitation. If I send text of 12 KBytes, the programs says 7300 bytes received.

Certainly TCP will send several packets - but the .NET documentation does not say if the Send() member function does any collation of packages or what. On MFC one had to use an CFile archive object with CSocket - is that needed too?

the client which sends to my server is some sample application which for sure can send at least 512 Kbytes in one go and has done so to other TCP servers without any trouble.


Expand|Select|Wrap|Line Numbers
  1.  
  2.             try
  3.             {
  4.                 int port = HostListenPort;
  5.                 int backlog = ListenBacklog;
  6.                 IPAddress hostIP = HostIPAddress;
  7.  
  8.                 IPEndPoint ep = new IPEndPoint(hostIP, port);
  9.                 listenSocket.Bind(ep);
  10.                 listenSocket.Listen(backlog);
  11.  
  12.                 MessageBox.Show("Listening has started.");
  13.  
  14.                 try
  15.                 {
  16.                        Socket cSocket= listenSocket.Accept();
  17.  
  18.                         MessageBox.Show("Accepted, and new socket created.);
  19.  
  20.  
  21.  
  22.                 cSocket.ReceiveBufferSize = 32768;
  23.                 byte[] recBuffer = new byte[32768];            
  24.                     int i = cSocket.Receive(recBuffer);
  25.                     String strRec = Encoding.UTF8.GetString(recBuffer);
  26.                         MessageBox.Show(Convert.ToString(iTot) + " bytes received.");
  27.  
  28.                 MessageBox.Show(strRec);
  29.  
  30.  
  31.                 }
  32.                 catch (Exception exptAccept)
  33.                 {
  34.                      String msg = "Error on accepting socket: " + exptAccept.ToString();
  35.                       MessageBox.Show(msg);
  36.                 }
  37.             }
  38.             catch (Exception exptConn)
  39.             {
  40.                 MessageBox.Show("Error on connection: " + exptConn.ToString());
  41.             }
  42.  
Mar 11 '08 #3
Plater
7,872 Expert 4TB
Well for starters, all of the data will not come in all at once, 7k is probably about all that makes it in before you do your reads. Have you tried to do another read, after allowing time for more data to arrive?

Also, I have not seen a backlog supplied since the days of C++, I don't think it's really needed?
Mar 11 '08 #4
Thanks - and this worked.
Obviously the RECEIVE method does not block until all is received ... no mention of this anywhere in the documentation though.

Concerning the Backlog entry - there is no overload which doesn't have this parameter, you'll have to supply it on the Accept() method.

Peter
Mar 12 '08 #5
Plater
7,872 Expert 4TB
Hmm, guess I don't do enough socket binding.
Also, there is a ReceiveBufferSize that is default to 8192 bytes, if that helps.
Mar 12 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Colin Brown | last post by:
Python2.3.2: Running the following receiver and sender code in separate windows under Win2K does not work properly (missed & very delayed transmissions). Under Redhat Linux 9 (where I will be using...
9
by: Phil Jenson | last post by:
I am try to evaluate the most efficient method of handling thousands of simultaneous TCP connects each of which remain connected to the server for hours and pass a small amount of data usually once...
1
by: Dan Kelley | last post by:
I have 2 projects - 1 Winform project that sends Udp messages using the UdpClient class when a button is clicked, and a Console application that listens for these Udp messages. If I try to use...
9
by: Stuart | last post by:
I am trying to execute a Socket.Select() statement on an arraylist of sockets. The problem is that I can only go up to 64 sockets at a time. I know that I have to manipulate the FD_SetSize to...
9
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so...
6
by: billie | last post by:
Hi all. I'm writing a TCP-based application that I will use to trasfer binary files through the network. This piece of code represents how do I get a file from a remote peer and save it on my local...
1
by: Sean | last post by:
Hi, I am trying to write a simple chat/text messaging program but I am having some problems. I am a rookie when it comes to socket programming so I am not sure if I am doing the write thing or...
3
by: doc | last post by:
What will a flash xml client socket connect to? I have a working php TCP/IP server socket bound to a port >1023 and the flash client will not even connect to it. I can connect to it with non-xml...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.