Advertisement

06.04.2008 at 06:25PM PDT, ID: 23458904
[x]
Attachment Details

TCP/IP comms (send jpg to port)

Asked by esps in Software/Systems Design, Visual Basic Programming, Microsoft Visual Basic.Net

Hi Experts
I have put together a simple send and receive module to send and receive a jpg file using TCP/IP.
Client is on a pc that connects to remote server where server module runs.
The code works fine in principle but the image received is corrupted (and smaller in size than the original).
I am including both send and receive snippets.
please help
regardsStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
Imports System.Net.Sockets
Imports System.Net
Imports System.Text
Imports System.IO
 
Server Module
_____________
 
        Const portNo As Integer = 2700
        Const BUFFER_SIZE As Integer = 10
        'Dim listener As New TcpListener(localAdd, portNo)
        Dim listener As New TcpListener(portNo)
        listener.Start()
        Console.WriteLine("Listening...")
        Dim tcpClient As TcpClient = listener.AcceptTcpClient()
        Dim NWStream As NetworkStream = tcpClient.GetStream
        Dim bytesToRead(tcpClient.ReceiveBufferSize) As Byte
        Dim numBytesRead, j As Integer
        '---read incoming stream and writing the bytes to file
        Const FILE_NAME = "c:\test_TCP_server\received.jpg"
        Dim fs As System.IO.FileStream
        fs = New FileStream(FILE_NAME, FileMode.CreateNew, FileAccess.Write)
        Do
            numBytesRead = NWStream.Read(bytesToRead, 0, BUFFER_SIZE)
            fs.Write(bytesToRead, 0, numBytesRead)
        Loop Until Not NWStream.DataAvailable
        fs.Close()
        tcpClient.Close()
        listener.Stop()
        MsgBox("received")
 
Client Module
_______________
 
Const portNo = 2700
        Const FILE_NAME = "c:\meter_pictures\c1m2.jpg"
        Dim tcpClient As New System.Net.Sockets.TcpClient
        tcpClient.Connect("zserver.i989.net", portNo)
        Dim NWStream As NetworkStream = tcpClient.GetStream
        Dim fs As FileStream
        Dim br As BinaryReader
        Dim numBytesRead As Integer
        fs = New FileStream(FILE_NAME, FileMode.Open, FileAccess.Read)
        br = New BinaryReader(fs)
        Dim bytesToSend(br.BaseStream.Length) As Byte
        numBytesRead = fs.Read(bytesToSend, 0, bytesToSend.Length)
        NWStream.Write(bytesToSend, 0, numBytesRead)
        MsgBox("sent!!")
        fs.Close()
        tcpClient.Close()
[+][-]06.04.2008 at 11:30PM PDT, ID: 21716786

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 11:46PM PDT, ID: 21716846

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.05.2008 at 12:31AM PDT, ID: 21717023

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.05.2008 at 06:44AM PDT, ID: 21719273

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.05.2008 at 07:00PM PDT, ID: 21725663

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.16.2008 at 06:30PM PDT, ID: 21798910

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.16.2008 at 11:51PM PDT, ID: 21800370

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.21.2008 at 12:00AM PDT, ID: 21836682

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.21.2008 at 03:32AM PDT, ID: 21837082

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Software/Systems Design, Visual Basic Programming, Microsoft Visual Basic.Net
Sign Up Now!
Solution Provided By: AkisC
Participating Experts: 2
Solution Grade: B
 
 
[+][-]06.21.2008 at 08:42AM PDT, ID: 21837830

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628