Click here to Skip to main content
15,898,373 members
Home / Discussions / C#
   

C#

 
GeneralRe: Trap Cancel Button Without Using MessageBox Class Pin
Win32SF14-Jun-08 13:38
Win32SF14-Jun-08 13:38 
Questionstoring an array in a profile tag of web.config Pin
Zeeshan Riaz14-Jun-08 11:01
Zeeshan Riaz14-Jun-08 11:01 
AnswerRe: storing an array in a profile tag of web.config Pin
Christian Graus14-Jun-08 11:14
protectorChristian Graus14-Jun-08 11:14 
GeneralRe: storing an array in a profile tag of web.config Pin
Zeeshan Riaz14-Jun-08 11:22
Zeeshan Riaz14-Jun-08 11:22 
GeneralRe: storing an array in a profile tag of web.config Pin
Christian Graus14-Jun-08 11:24
protectorChristian Graus14-Jun-08 11:24 
GeneralRe: storing an array in a profile tag of web.config Pin
Zeeshan Riaz14-Jun-08 11:34
Zeeshan Riaz14-Jun-08 11:34 
GeneralRe: storing an array in a profile tag of web.config Pin
Christian Graus14-Jun-08 11:35
protectorChristian Graus14-Jun-08 11:35 
Questionsocket usage permission Pin
mahraja14-Jun-08 9:41
mahraja14-Jun-08 9:41 
Hi I recieve this exception:
"Only one usage of each socket address (protocol/network address/port) is normally permitted"

I should get several files from an ftp server. I implemented it by sockets so: create the datasocket, recieve the file and then close data socket. But the next time I do this for another file(create data socket with Endpoint (the same local address/another port)), i recieve this exception message when Binding the socket. Can anyone tell me why? And the way to solve that?

(the code, if necessary)
public void download(string remFileName, string locFileName)
{
    if (!logined)
    {
        login();
    }

    setBinaryMode(true);
    Console.WriteLine("Downloading file " + remFileName + " from " + remoteHost + "/" + remotePath);

    if (locFileName.Equals(""))
    {
        locFileName = remFileName;
    }

    if (!File.Exists(locFileName))
    {
        Stream st = File.Create(locFileName);
        st.Close();
    }

    FileStream output = new FileStream(locFileName, FileMode.Open);

    createDataSocket(true);
    if (dataSocket != null)
    {
        throw new SocketException();
    }
    //****
    sendCommand("RETR " + remFileName);

    if (!(retValue == 150 || retValue == 125))
    {
        throw new IOException(reply.Substring(4));
    }
    //****

    dataSocket = listeningSocket.Accept();
    listeningSocket.Close();
    listeningSocket = null;
    if (dataSocket == null)
    {
        throw new Exception("Winsock error: " +
                Convert.ToString(System.Runtime.InteropServices.Marshal.GetLastWin32Error()));
    }

    while (true)
    {
        bytes = dataSocket.Receive(buffer, buffer.Length, 0);
        output.Write(buffer, 0, bytes);

        if (bytes <= 0)
        {
            break;
        }
    }

    output.Close();

    if (dataSocket.Connected)
    {
        //dataSocket.Shutdown(SocketShutdown.Both);
        dataSocket.Close();
        dataSocket = null;
    }

    Console.WriteLine("");

    readReply();

    if (!(retValue == 226 || retValue == 250))
    {
        throw new IOException(reply.Substring(4));
    }
}


public void createDataSocket(bool flag)
{
    try
    {
        listeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    }
    catch (Exception e)
    {
        ftpLog(e.Message);
        throw new IOException(e.Message);
    }

    string localAddress = clientSocket.LocalEndPoint.ToString();
    int ix = localAddress.IndexOf(':');
    if (ix < 0)
        throw new Exception("local IP ERROR");

    string localIP = localAddress.Substring(0, ix);
    IPEndPoint localEP = new IPEndPoint(IPAddress.Parse(localIP), localDataPort);

    try
    {
        //listeningSocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.ReuseAddress, false);
        <big>listeningSocket.Bind(localEP);//second execution of this line causes the exception</big>
        listeningSocket.Listen(1);
    }
    catch (SocketException se)
    {
        ftpLog(se.Message);
        throw new IOException(se.Message);
    }

    localIP = localIP.Replace('.', ',');
    string portCMD = string.Format("PORT {0},{1},{2}", localIP, localDataPort / 256, localDataPort % 256);

    localDataPort++;

    sendCommand(portCMD);
    if(retValue!=200)
        throw new IOException(reply.Substring(4));
}

QuestionExcel Help Pin
MumbleB14-Jun-08 6:22
MumbleB14-Jun-08 6:22 
AnswerRe: Excel Help Pin
parth.p14-Jun-08 16:06
parth.p14-Jun-08 16:06 
QuestionC# navigating to top of page Pin
nyjcr14-Jun-08 5:43
nyjcr14-Jun-08 5:43 
AnswerRe: C# navigating to top of page Pin
N a v a n e e t h14-Jun-08 5:55
N a v a n e e t h14-Jun-08 5:55 
Questionhow to can i run or execute another program from C# ... like winword for example ?? Pin
Zero coder14-Jun-08 3:44
Zero coder14-Jun-08 3:44 
AnswerRe: how to can i run or execute another program from C# ... like winword for example ?? Pin
Christian Graus14-Jun-08 3:47
protectorChristian Graus14-Jun-08 3:47 
AnswerRe: how to can i run or execute another program from C# ... like winword for example ?? [modified] Pin
erfi15-Jun-08 4:20
erfi15-Jun-08 4:20 
QuestionProblem for CCD Image Display in my Application Pin
PowerOn14-Jun-08 2:41
PowerOn14-Jun-08 2:41 
AnswerRe: Problem for CCD Image Display in my Application Pin
Christian Graus14-Jun-08 3:47
protectorChristian Graus14-Jun-08 3:47 
QuestionHelp: ReadPrint(winspool) & C# Pin
_CMD_14-Jun-08 2:26
_CMD_14-Jun-08 2:26 
QuestionInvoking SSIS PAckage from C# Pin
Member 400849213-Jun-08 22:40
Member 400849213-Jun-08 22:40 
QuestionNear-static class [modified] Pin
PIEBALDconsult13-Jun-08 13:25
mvePIEBALDconsult13-Jun-08 13:25 
AnswerRe: Near-static class Pin
MarkB77713-Jun-08 14:29
MarkB77713-Jun-08 14:29 
GeneralRe: Near-static class Pin
PIEBALDconsult13-Jun-08 15:28
mvePIEBALDconsult13-Jun-08 15:28 
GeneralRe: Near-static class Pin
MarkB77713-Jun-08 16:01
MarkB77713-Jun-08 16:01 
GeneralRe: Near-static class Pin
leppie13-Jun-08 21:56
leppie13-Jun-08 21:56 
GeneralRe: Near-static class Pin
PIEBALDconsult16-Jun-08 10:01
mvePIEBALDconsult16-Jun-08 10:01 

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.