473,405 Members | 2,210 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,405 software developers and data experts.

Reading from sockets

1
Hi,

I am trying to make a really basic server that echoes whatever it receives from the client connected to it. Catch being the client is written in c++. The client sends an initiating packet to the server, which I am trying to echo to output.

I am using BufferedReader to read the incoming data from the socket. The problem is that even if I read each char, I cannot read the last char of incoming stream until the client disconnects.

When I use BufferedReader.readLine(), the server won't print anything until the client disconnects and then it prints the whole packet.

When I use BufferedReader.read(), to read single bytes and print them onto screen, all the bytes save the last get written to output. The last byte gets written when client disconnects.

I have been searching for a solution to this for quiet some time now.

The server code otherwise is fine, because if I telnet to the same port, the server echos perfectly.

In the past I have used a simple server written in C to echo everything from the same client.

I am not sure where the problem is, and any help or pointers would be highly appreciated.

-Q
Nov 5 '08 #1
2 1643
r035198x
13,262 8TB
Perhaps there is a problem in your code for reading the data. Could you post that part of the code?
Nov 6 '08 #2
Nepomuk
3,112 Expert 2GB
Another idea: Does the server flush the output before it is closed? If not, doing so may solve the problem.

Greetings,
Nepomuk
Nov 10 '08 #3

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

Similar topics

9
by: javastudent | last post by:
Hi, I am implementing a server that reads for socket connections at a port, and processes the socket on a separate thread. We do not control the client implementation. Here is the scenario. ...
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
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
3
by: Michael Maercker | last post by:
hi! i'm really not into networking at all and have now been asigned the task of porting a vb6-code into vb.net (compact framework, in this case) and the code uses the winsock-control. i quickly...
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...
0
by: =?Utf-8?B?R3JlZw==?= | last post by:
I am trying to read text from a Telnet site melvyl.ucop.edu. I run the following VB .NET 2003 code: Dim nstc As New Net.Sockets.TcpClient("melvyl.ucop.edu", 23) Dim nsns As...
2
by: Benoit | last post by:
I got myself into programming late in the summer and have dabbled in python for the most part in that time, recently beginning work on a music player. In January, I start my minor in Information...
0
by: Bruno Rafael Moreira de Barros | last post by:
Hey there. I have a small problem with sockets. The code is really simple, but it still fails. The problem is I am accessing a .rar file (for those who don't know it's an archive, like .zip)...
10
by: puzzlecracker | last post by:
Say I want to arrange bytes in the internal buffer in a certain way. I receive those bytes in the socket. One solution is to read in socket in pieces: byte buffer = new byte; int index = 0;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.