Click here to Skip to main content
15,905,015 members
Home / Discussions / C#
   

C#

 
AnswerRe: What is the code for Credit card no. validation in C#? Pin
PIEBALDconsult23-Dec-10 4:45
mvePIEBALDconsult23-Dec-10 4:45 
GeneralRe: What is the code for Credit card no. validation in C#? Pin
Cnu5555529-Dec-10 17:55
Cnu5555529-Dec-10 17:55 
AnswerRe: What is the code for Credit card no. validation in C#? Pin
jschell23-Dec-10 7:05
jschell23-Dec-10 7:05 
GeneralRe: What is the code for Credit card no. validation in C#? Pin
Cnu5555529-Dec-10 17:49
Cnu5555529-Dec-10 17:49 
AnswerRe: What is the code for Credit card no. validation in C#? Pin
DaveyM6923-Dec-10 13:27
professionalDaveyM6923-Dec-10 13:27 
AnswerRe: What is the code for Credit card no. validation in C#? Pin
Dr.Walt Fair, PE23-Dec-10 15:28
professionalDr.Walt Fair, PE23-Dec-10 15:28 
GeneralRe: What is the code for Credit card no. validation in C#? Pin
Cnu5555529-Dec-10 17:41
Cnu5555529-Dec-10 17:41 
AnswerRe: What is the code for Credit card no. validation in C#? Pin
LloydA11126-Dec-10 4:54
LloydA11126-Dec-10 4:54 
AnswerRe: What is the code for Credit card no. validation in C#? Pin
Bernhard Hiller27-Dec-10 23:08
Bernhard Hiller27-Dec-10 23:08 
QuestionEnterprise Library V5 Logging Pin
Ray Cassick22-Dec-10 21:14
Ray Cassick22-Dec-10 21:14 
AnswerRe: Enterprise Library V5 Logging Pin
dan!sh 22-Dec-10 21:36
professional dan!sh 22-Dec-10 21:36 
GeneralRe: Enterprise Library V5 Logging Pin
Ray Cassick22-Dec-10 21:46
Ray Cassick22-Dec-10 21:46 
GeneralRe: Enterprise Library V5 Logging Pin
dan!sh 22-Dec-10 21:53
professional dan!sh 22-Dec-10 21:53 
GeneralRe: Enterprise Library V5 Logging Pin
Ray Cassick22-Dec-10 22:10
Ray Cassick22-Dec-10 22:10 
QuestionLooking at the remote desktop template, help with automating acknowledgement of the legal banner [modified] Pin
turbosupramk322-Dec-10 8:26
turbosupramk322-Dec-10 8:26 
AnswerRe: Looking at the remote desktop template, help with automating acknowledgement of the legal banner Pin
Richard MacCutchan22-Dec-10 8:59
mveRichard MacCutchan22-Dec-10 8:59 
AnswerRe: Looking at the remote desktop template, help with automating acknowledgement of the legal banner [modified] Pin
RaviRanjanKr22-Dec-10 17:39
professionalRaviRanjanKr22-Dec-10 17:39 
GeneralRe: Looking at the remote desktop template, help with automating acknowledgement of the legal banner Pin
turbosupramk323-Dec-10 0:16
turbosupramk323-Dec-10 0:16 
QuestionHow do I transfer files over a local network? Pin
Megidolaon22-Dec-10 7:12
Megidolaon22-Dec-10 7:12 
I've tried a ton of tutorials but none work. Or rather, sooner or later ALL digress and leave the crucial part of transfering a file that isn't pure text.

I'm remodeling an app I've previously used to transfer text and project specific objects over a LAN. I'm just having trouble to receive the file and save it again after the transfer (I assume the sending of the file is successful, but of course have no way to actually verify this).

Here is the code for my client (sending) app:
private void Send(string arg)
{
    TcpClient client = new TcpClient(TB_Host.Text, (int)UD_Port.Value);
    FileStream fstream = File.Open(OFD_File.FileName, FileMode.Open);
    NetworkStream nstream = client.GetStream();
    int data = 0;

    while (data > 0)
    {
        data = fstream.ReadByte();
        nstream.WriteByte((byte)data);
    }

    fstream.Close();
    nstream.Close();
    client.Close();
}
And this is the code for the server (receiving) app:
public void Listen()
        {
            int port = 21112;
            byte[] result = new byte[1024];
            IPAddress address = IPAddress.Parse("127.0.0.1");
            TcpListener listener = new TcpListener(address, port);
            ipEnd = new IPEndPoint(address, port);
            listener.Start();
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            int f = 0;
            object state = new object();
            socket.Connect(ipEnd);

            while (true)
            {
                TcpClient client = listener.AcceptTcpClient();
                NetworkStream ns = client.GetStream();

                f = socket.Receive(result);
                Invoke(new UpdateDisplayDelegate(UpdateDisplay), result);
            }
        }
The current problem is that the code never reaches the invoke call (the Listen method is on a 2nd thread), which confuses me as there never had been any problem when I transferred text or objects.

I tried a SoapFormatter, but while it works great for text and objects, I can't get it to work for files.
I also tried using no sockets but a NetworkStream to write into the buffer:
result = ns.Write(result, 0, int.MaxValue);
but I always get an ArgumentOutOfRange exception for the size (I used int.MaxValue) parameter.

Can you tell me how to get it to work? Or is this approach wrong in the first place?
Thanks!
AnswerRe: How do I transfer files over a local network? PinPopular
Luc Pattyn22-Dec-10 8:54
sitebuilderLuc Pattyn22-Dec-10 8:54 
GeneralRe: How do I transfer files over a local network? Pin
Megidolaon22-Dec-10 10:12
Megidolaon22-Dec-10 10:12 
GeneralMy vote of 1 Pin
Keith Barrow22-Dec-10 10:33
professionalKeith Barrow22-Dec-10 10:33 
GeneralRe: My vote of 1 Pin
Megidolaon23-Dec-10 7:55
Megidolaon23-Dec-10 7:55 
GeneralRe: My vote of 1 Pin
Keith Barrow23-Dec-10 7:59
professionalKeith Barrow23-Dec-10 7:59 
GeneralRe: How do I transfer files over a local network? Pin
Henry Minute22-Dec-10 10:34
Henry Minute22-Dec-10 10:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.