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

.NET (Core and Framework)

 
QuestionDeployment / Permissions for control embedded in a web page Pin
sitruc711-Jan-10 5:19
sitruc711-Jan-10 5:19 
AnswerRe: Deployment / Permissions for control embedded in a web page Pin
Eddy Vluggen13-Jan-10 8:26
professionalEddy Vluggen13-Jan-10 8:26 
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 
hi......
i just want to convert an arraylist into bytearray via object in clientside and again convert this bytearray into arraylist in server side.could somebody help me on this.
i tried a lot.
the arraylist contents are from a file whose name is obtained in client.
but i could not get the answer.
i would be thankful to you...
my codings are as follows:

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
{
[Serializable]
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();

byte[] buf = new byte[1024];
cli.Receive(buf);
Object obj = new Object();
obj = bytearraytoobject(buf);

ArrayList al = obj as ArrayList;
int i = 0;
foreach (Object o in al)
{
Console.WriteLine("\t[{0}]:\t{1}", i++, o);
}
Console.WriteLine();
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;
}

}
}

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
{
[Serializable]
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);

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();
}
}
}
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 
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 

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.