If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Reading File in .NET

I have a strange problem in my present project. I am creating a server in
VB.NET that accepts request from multiple clients. Each client passes a text
file to the server to read. There is no problem with the client code.

When I am reading the data from the text file in the server

Public Sub Main1(ByVal iJobNo As Integer)
Dim soc As Socket = tcpListener.AcceptSocket()
Try
Dim s As Stream = New NetworkStream(soc)
Dim sr As New StreamReader(s)
Dim sw As New StreamWriter(s)
sw.AutoFlush = True
Do
---PROBLEM LINE--- Dim name As String = sr.ReadLine()
If InStr(name, "*", CompareMethod.Text) = 3 Then
sUsrDetails(iJobNo) = name
Exit Do
End If
If name = "" Or name Is Nothing Then Exit Do
Loop
s.Close()
soc.Close()
End Sub

The streamReader(sr) sr.ReadLine() statement abruptly ends after it reads
the last line and does not go the verify the InStr method.

The problem is it does work some time with the same code without any changes
being made.. but most other times it does not work.. this is strange though..
Pls let me know, if u can help me out here.. thanks in advance

Re: Reading File in .NET

On the ones that just stop, does the text file have a concluding CrLF? I
have seen cases where StringReader seems to require it when reading from
memorystreams.

HTH
"Sathya" <sathya76@yahoo.com> wrote in message news:3d1352e9$1@10.1.10.29...
>
> I have a strange problem in my present project. I am creating a server in
> VB.NET that accepts request from multiple clients. Each client passes a
text
> file to the server to read. There is no problem with the client code.
>
>
> When I am reading the data from the text file in the server
>
> Public Sub Main1(ByVal iJobNo As Integer)
> Dim soc As Socket = tcpListener.AcceptSocket()
> Try
> Dim s As Stream = New NetworkStream(soc)
> Dim sr As New StreamReader(s)
> Dim sw As New StreamWriter(s)
> sw.AutoFlush = True
> Do
> ---PROBLEM LINE--- Dim name As String = sr.ReadLine()
> If InStr(name, "*", CompareMethod.Text) = 3 Then
> sUsrDetails(iJobNo) = name
> Exit Do
> End If
> If name = "" Or name Is Nothing Then Exit Do
> Loop
> s.Close()
> soc.Close()
> End Sub
>
> The streamReader(sr) sr.ReadLine() statement abruptly ends after it reads
> the last line and does not go the verify the InStr method.
>
> The text file is
>
> //A9FRT1 JOB (A9FRT,AAIS),'TECHReports',CLASS=A,REGION=4M,MSGCLASS=Z,
> // MSGLEVEL=(0,0),PASSWORD=HANDY
> /*JOBPARM T=999,L=999
> //LASER OUTPUT DEST=RMT10,FORMDEF=10FD,PAGEDEF=05PD
> //PROC JCLLIB ORDER=AIS95.SISPROD.PROCLIB
> //FOCUS1 EXEC FCSP,USEDBY=A2SYR,SYSTEM=PROD,NODE=95
> //SYSPRINT DD SYSOUT=W
> //OFFLINE DD SYSOUT=W,OUTPUT=*.LASER,
> // DATACLAS=TTUFBA,DCB=(BLKSIZE=133)
> //SYSIN DD *
> EX FFR054 TERM_CYT=19991,
> DEPT=HIST
> FIN
> /*
> //
> //*a9frt,handy,sathya76@yahoo.com,c:\temp\tempJCL.trd
>
>
> The problem is it does work some time with the same code without any
changes
> being made.. but most other times it does not work.. this is strange
though..
> Pls let me know, if u can help me out here.. thanks in advance
>
> Sathya

Re: Reading File in .NET

I am not sure I can completely solve your problem, but it seems to me that
you need to rework your Dim statements (you are mixing and matching different
objects). I am eclosing some source code that demonstrates creating a stream
for reading and writing. See if this helps you locate your error.
Public Sub RunServer()
Dim listener As TcpListener
Dim counter As Integer = 1

Re: Reading File in .NET

Once again, I don't know if I can solve your problem for you, but
I keep looking at your DO loop. Is it a DO WHILE or DO UNTIL loop?
Unless something is missing from this piece of code, I can't see
where you have stated any conditions to DO. So the program never enters
the DO LOOP; it just opens a Stream for Reading, opens a Stream for Writing
then closes each stream; which sounds like what you are experiencing.

PW

Public Sub Main1(ByVal iJobNo As Integer)
Dim soc As Socket = tcpListener.AcceptSocket()
Try
Dim s As Stream = New NetworkStream(soc)
Dim sr As New StreamReader(s)
Dim sw As New StreamWriter(s)
sw.AutoFlush = True
Do
---PROBLEM LINE--- Dim name As String = sr.ReadLine()
If InStr(name, "*", CompareMethod.Text) = 3 Then
sUsrDetails(iJobNo) = name
Exit Do
End If
If name = "" Or name Is Nothing Then Exit Do
Loop
s.Close()
soc.Close()
End Sub

The streamReader(sr) sr.ReadLine() statement abruptly ends after it reads
the last line and does not go the verify the InStr method.

The problem is it does work some time with the same code without any
changes
being made.. but most other times it does not work.. this is strange
though..
Pls let me know, if u can help me out here.. thanks in advance