Click here to Skip to main content
15,900,724 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problems with directsound notify Pin
grarup26-Mar-09 1:28
grarup26-Mar-09 1:28 
GeneralRe: Problems with directsound notify Pin
DaveyM6926-Mar-09 2:17
professionalDaveyM6926-Mar-09 2:17 
GeneralRe: Problems with directsound notify Pin
grarup26-Mar-09 3:03
grarup26-Mar-09 3:03 
AnswerRe: Problems with directsound notify Pin
Henry Minute26-Mar-09 3:20
Henry Minute26-Mar-09 3:20 
GeneralRe: Problems with directsound notify Pin
DaveyM6926-Mar-09 3:25
professionalDaveyM6926-Mar-09 3:25 
GeneralRe: Problems with directsound notify Pin
Henry Minute26-Mar-09 3:33
Henry Minute26-Mar-09 3:33 
QuestionSend and Recive files using Socket Pin
yesu prakash25-Mar-09 23:27
yesu prakash25-Mar-09 23:27 
AnswerRe: Send and Recive files using Socket Pin
annapurna.tiwari25-Mar-09 23:48
annapurna.tiwari25-Mar-09 23:48 
Please try this

//Client Socket code

/* Make IP end point same as Server. */
Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
/* Make a client socket to send data to server. */

string filePath = "";
/* File reading operation. */
fileName = fileName.Replace("\\", "/");
while (fileName.IndexOf("/") > -1)
{
filePath += fileName.Substring(0, fileName.IndexOf("/") + 1);
fileName = fileName.Substring(fileName.IndexOf("/") + 1);
}


byte[] fileNameByte = Encoding.ASCII.GetBytes(fileName);
if (fileNameByte.Length > 850 * 1024)
{
curMsg = "File size is more than 850kb, please try with small file.";
return;
}

curMsg = "Buffering ...";
byte[] fileData = File.ReadAllBytes(filePath + fileName);

/* Read & store file byte data in byte array. */
byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length];

/* clientData will store complete bytes which will store file name length, file name & file data. */
byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length);
/* File name length’s binary data. */
fileNameLen.CopyTo(clientData, 0);
fileNameByte.CopyTo(clientData, 4);
fileData.CopyTo(clientData, 4 + fileNameByte.Length);
/* copy these bytes to a variable with format line [file name length][file name] [ file content] */
curMsg = "Connection to server ...";
clientSock.Connect(ipEnd);

/* Trying to connection with server. /

curMsg = "File sending...";
clientSock.Send(clientData);
/* Now connection established, send client data to server. */
curMsg = "Disconnecting...";
clientSock.Close();

/* Data send complete now close socket. */
curMsg = "File transferred.";


//Server Scoket Code
//Make IP end point to accept any IP address with port no 5656.

sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);

//Here creating new socket object with protocol type and transfer data type
sock.Bind(ipEnd);

//Bind end point with newly created socket.
}
public static string receivedPath;
public static string curMsg = "Stopped";
public void StartServer()
{
try
{
curMsg = "Starting...";
sock.Listen(100);
/* That socket object can handle maximum 100 client connection at a time & waiting for new client connection /
curMsg = "Running and waiting to receive file.";
Socket clientSock = sock.Accept();
/* When request comes from client that accept it and return new socket object for handle that client. */
byte[] clientData = new byte[1024 * 5000];

int receivedBytesLen = clientSock.Receive(clientData);
curMsg = "Receiving data...";

int fileNameLen = BitConverter.ToInt32(clientData, 0);

/* I’ve sent byte array data from client in that format like [file name length in byte][file name] [file data], so need to know first how long the file name is. /
string fileName = Encoding.ASCII.GetString(clientData, 4, fileNameLen);
/* Read file name */
BinaryWriter bWrite = new BinaryWriter(File.Open(receivedPath +"/"+ fileName, FileMode.Append)); ;

/* Make a Binary stream writer to saving the receiving data from client. /
bWrite.Write(clientData, 4 + fileNameLen, receivedBytesLen - 4 - fileNameLen);
/* Read remain data (which is file content) and save it by using binary writer. */
curMsg = "Saving file...";

bWrite.Close();
clientSock.Close();

/* Close binary writer and client socket */
curMsg = "Reeived & Saved file; Server Stopped.";



Hope that it will solve your problem

Thanks
Annapurna
Questionabout database Pin
dcyuhi25-Mar-09 23:26
dcyuhi25-Mar-09 23:26 
AnswerRe: about database Pin
Tom Deketelaere25-Mar-09 23:36
professionalTom Deketelaere25-Mar-09 23:36 
AnswerRe: about database Pin
Deresen26-Mar-09 0:00
Deresen26-Mar-09 0:00 
GeneralRe: about database Pin
dcyuhi26-Mar-09 0:26
dcyuhi26-Mar-09 0:26 
GeneralRe: about database Pin
Deresen26-Mar-09 0:56
Deresen26-Mar-09 0:56 
GeneralRe: about database Pin
Tom Deketelaere26-Mar-09 1:14
professionalTom Deketelaere26-Mar-09 1:14 
GeneralRe: about database Pin
Deresen26-Mar-09 1:18
Deresen26-Mar-09 1:18 
GeneralRe: about database Pin
Tom Deketelaere26-Mar-09 1:32
professionalTom Deketelaere26-Mar-09 1:32 
GeneralRe: about database Pin
Deresen26-Mar-09 1:37
Deresen26-Mar-09 1:37 
AnswerRe: about database Pin
Mirko198026-Mar-09 0:37
Mirko198026-Mar-09 0:37 
GeneralRe: about database Pin
dcyuhi26-Mar-09 4:44
dcyuhi26-Mar-09 4:44 
AnswerRe: about database Pin
Michael Bookatz26-Mar-09 1:07
Michael Bookatz26-Mar-09 1:07 
QuestionHow to check a email id is valid or not Pin
Sayantan Basu25-Mar-09 23:12
Sayantan Basu25-Mar-09 23:12 
AnswerRe: How to check a email id is valid or not Pin
Eddy Vluggen25-Mar-09 23:20
professionalEddy Vluggen25-Mar-09 23:20 
Questionnot able to view Picture box on the form Pin
saksp25-Mar-09 23:12
saksp25-Mar-09 23:12 
AnswerRe: not able to view Picture box on the form Pin
Tom Deketelaere25-Mar-09 23:16
professionalTom Deketelaere25-Mar-09 23:16 
AnswerRe: not able to view Picture box on the form Pin
N a v a n e e t h25-Mar-09 23:18
N a v a n e e t h25-Mar-09 23:18 

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.