Click here to Skip to main content
16,004,828 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionAccess data in a remote server Pin
jonatan_55611-Jan-10 1:39
jonatan_55611-Jan-10 1:39 
AnswerRe: Access data in a remote server Pin
dan!sh 11-Jan-10 3:39
professional dan!sh 11-Jan-10 3:39 
GeneralRe: Access data in a remote server Pin
jonatan_55611-Jan-10 4:08
jonatan_55611-Jan-10 4:08 
QuestionDesig VB.net Table Pin
Thomas O'Donoghue10-Jan-10 1:51
Thomas O'Donoghue10-Jan-10 1:51 
AnswerRe: Desig VB.net Table Pin
Ashfield10-Jan-10 5:43
Ashfield10-Jan-10 5:43 
Questionarraylist to byte array & viceversa---plz. help me....... Pin
thivya n9-Jan-10 19:16
thivya n9-Jan-10 19:16 
AnswerRe: arraylist to byte array & viceversa---plz. help me....... Pin
Luc Pattyn10-Jan-10 0:57
sitebuilderLuc Pattyn10-Jan-10 0:57 
AnswerRe: arraylist to byte array & viceversa---plz. help me....... Pin
thivya n10-Jan-10 3:01
thivya n10-Jan-10 3:01 
thank you very much for ur kind reply........
i have worked on it and found the solution by myself.

anyway please help me on my later questions regarding my doubts in .net.......
actually it is to generate some random questions by sending the file contenets from client to server and then the server should generate random questions(say 5) from it and the send back to the client.....
THANKS FOR THIS...
ADVANCE THANKS to answer for my later questions.

my code is as follws:
Server:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            IPEndPoint ip = new IPEndPoint(IPAddress.Any, 9999);
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            s.Bind(ip);
            s.Listen(10);
            Console.WriteLine("Waiting for a client...");
            Socket cli = s.Accept();
            IPEndPoint cliep = (IPEndPoint)cli.RemoteEndPoint;
            Console.WriteLine("Connected with {0} at port {1}", cliep.Address, cliep.Port);

            byte[] buffer = new byte[1024];
            cli.Receive(buffer);
            string fname = Encoding.ASCII.GetString(buffer);

            Console.WriteLine("filename is " + fname);
            Console.ReadLine();
                       
            cli.Receive(buffer);
            Object obj = new Object();
            obj = bytearraytoobject(buffer);

            ArrayList al = (ArrayList)obj;
            int i = 0;
            foreach (Object o in al)
            {
                Console.WriteLine("\t[{0}]:\t{1}", i++, o);
            }
            Console.WriteLine();

            ArrayList qal=new ArrayList();
            Random rnd = new Random(DateTime.Now.Millisecond);
            for (int counter = 0; counter < 5; counter++)
            {
                int randomindex = rnd.Next(al.Count);
                Console.WriteLine("{0}:{1}", counter+ 1, al[randomindex]);
                qal.Add(al[randomindex]);
            }

            foreach (Object o in qal)
            {
                Console.WriteLine("\t[{0}]:\t{1}", i++, o);
            }

            Object ob = (Object)qal;            
            buffer = objecttobytearray(ob);
            cli.Send(buffer);
            
            Console.ReadLine();

        }
        static Object bytearraytoobject(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            ms.Write(buffer, 0, buffer.Length);
            ms.Seek(0, SeekOrigin.Begin);
            Object obj = (Object)bf.Deserialize(ms);
            return obj;
        }
        static byte[] objecttobytearray(Object obj)
        {
            if (obj == null)
                return null;
            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            bf.Serialize(ms, obj);
            return ms.ToArray();
        }

    }
}


client:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            IPEndPoint ip = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9999);

            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                s.Connect(ip);
            }
            catch (SocketException e)
            {
                Console.WriteLine("Unable to connect to server" + e);
                return;
            }

            Console.WriteLine("Enter the input file ");
            string inp = Console.ReadLine();

            s.Send(Encoding.ASCII.GetBytes(inp));

            StreamReader sr = new StreamReader(@"c:\" + inp);
            ArrayList al = new ArrayList();

            while (!sr.EndOfStream)
            {
                al.Add(sr.ReadLine());
            }

            Object o = (Object)al;
            byte[] buffer = new byte[1024];
            buffer = objecttobytearray(o);
            s.Send(buffer);

            byte[] buf = new byte[1024];
            Object obj = new Object();
            s.Receive(buf);                        
            obj = bytearraytoobject(buf);
            ArrayList qal = (ArrayList)obj;

            int i = 1;
            foreach (Object ob in qal)
            {
                Console.WriteLine("\t[{0}]:\t{1}", i++, ob);
            }
            Console.WriteLine();

            Console.ReadLine();

        }
        static byte[] objecttobytearray(Object obj)
        {
            if (obj == null)
                return null;
            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            bf.Serialize(ms, obj);
            return ms.ToArray();
        }
        static Object bytearraytoobject(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            ms.Write(buffer, 0, buffer.Length);
            ms.Seek(0, SeekOrigin.Begin);
            Object obj = (Object)bf.Deserialize(ms);
            return obj;
        }
    }
}

QuestionMessageBox with custom background color Pin
peterdrozd8-Jan-10 5:07
peterdrozd8-Jan-10 5:07 
AnswerRe: MessageBox with custom background color Pin
Richard MacCutchan8-Jan-10 5:21
mveRichard MacCutchan8-Jan-10 5:21 
GeneralRe: MessageBox with custom background color Pin
peterdrozd8-Jan-10 10:54
peterdrozd8-Jan-10 10:54 
GeneralRe: MessageBox with custom background color Pin
Richard MacCutchan8-Jan-10 22:15
mveRichard MacCutchan8-Jan-10 22:15 
AnswerRe: MessageBox with custom background color Pin
Palash Biswas4-Feb-10 2:24
Palash Biswas4-Feb-10 2:24 
QuestionRich text box equivalent textbox Pin
Ajakblackgoat7-Jan-10 20:54
Ajakblackgoat7-Jan-10 20:54 
AnswerRe: Rich text box equivalent textbox [modified] Pin
Eddy Vluggen7-Jan-10 23:38
professionalEddy Vluggen7-Jan-10 23:38 
GeneralRe: Rich text box equivalent textbox Pin
Luc Pattyn8-Jan-10 3:15
sitebuilderLuc Pattyn8-Jan-10 3:15 
GeneralRe: Rich text box equivalent textbox Pin
Ajakblackgoat8-Jan-10 4:27
Ajakblackgoat8-Jan-10 4:27 
GeneralRe: Rich text box equivalent textbox Pin
Eddy Vluggen8-Jan-10 5:47
professionalEddy Vluggen8-Jan-10 5:47 
GeneralRe: Rich text box equivalent textbox Pin
Ajakblackgoat8-Jan-10 14:06
Ajakblackgoat8-Jan-10 14:06 
GeneralRe: Rich text box equivalent textbox Pin
Eddy Vluggen9-Jan-10 1:13
professionalEddy Vluggen9-Jan-10 1:13 
AnswerRe: Rich text box equivalent textbox Pin
Luc Pattyn8-Jan-10 2:15
sitebuilderLuc Pattyn8-Jan-10 2:15 
GeneralRe: Rich text box equivalent textbox Pin
Ajakblackgoat8-Jan-10 4:45
Ajakblackgoat8-Jan-10 4:45 
GeneralRe: Rich text box equivalent textbox Pin
Luc Pattyn8-Jan-10 4:55
sitebuilderLuc Pattyn8-Jan-10 4:55 
QuestionHow to create a taskbar in mdiform.. just like windows in vb.net code Pin
chandru4uall6-Jan-10 23:21
chandru4uall6-Jan-10 23:21 
Questionset default icon in windows app Pin
vikash_singh6-Jan-10 5:55
vikash_singh6-Jan-10 5:55 

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.