Showing posts with label web development. Show all posts
Showing posts with label web development. Show all posts

Thursday, May 5, 2016

How to include Web Fonts in my website

Problem:
I need to include specific font (Futura Bold for my case) in my website but it is not supporting it, whenever I am trying to include it is not reflecting in browser. I double check my HTML and CSS syntax, everything fine but still there has no effect. What is the problem?

Web font what it is?
I am facing the problem just because of the desire font is not standard web fonts hence it is not getting effect. Solution is convert font as web standard and include in project, after that I can use it. Next problem, How?

How to generated any font as web standard font (webfonts)?
Conversion font to webstandard is very easy if you know it. However its not difficult. 
There has multiple website to generate webfonts. I have used https://www.fontsquirrel.com/tools/webfont-generator to generate webfonts. This is very easy process, just upload the font and generate it. If the font is not available to you you can download it from website. I have downloaded Futura font from http://www.futurafontfree.com/fonts/futura-book-font-free-download.
The generated webfonts downloaded as zip and after unzip the folder looks like below.


Generated folder comes with multiple files including stylesheet.css file. All of these files I need and might need to edit stylesheet.css file. Initially the style sheet file code looks as 



@font-face {    font-family: 'futura_urw_extra_boldregular';    src: url('futurat_bold-webfont.eot');    src: url('futurat_bold-webfont.eot?#iefix') format('embedded-opentype'),         url('futurat_bold-webfont.woff2') format('woff2'),         url('futurat_bold-webfont.woff') format('woff'),         url('futurat_bold-webfont.ttf') format('truetype'),         url('futurat_bold-webfont.svg#futura_urw_extra_boldregular') format('svg');    font-weight: normal;    font-style: normal;
}

Basically these code is referring to generated files. Keep it as it is.

Include generated webfonts in my project.
Add the folder with all files in my project and next need need to add reference. My complete project is looks like 



To include stylesheet in project is very common as we do always. Just add stylesheet by below code:

<link rel="stylesheet" href="stylesheet.css" type="text/css" charset="utf-8" />

Change font-family with new font in your code and its done, now run it from browser.



Download complete project from following URL.

https://drive.google.com/file/d/0Bwd4GP6MNsEgN3BSdnI4Y3Zhak0/view?usp=sharing 




Tuesday, January 14, 2014

Real time chat application on Web in ASP.Net using SignalR technology : Introduction

I shall start posting code and description about how to create web chat application in asp.net using .Net's latest technology SignalR step by step. Also I shall share how to create server event based application. Already I have developed this chat server and using in my social website http://alap.me.

However I shall start posting on it step by step so a learner can learn it easily. I shall start from very begging with many small small things and shall cover ASP.Net parts and related stuff like jQuery, CSS, HTML5 or normal java script. Because all of these things will require to build full complete chat application.

The same code I shall share which I have used in my social network site chat part. I shall publish my code as open source so any one can use it in his application and any one can enhance it so other people can use it as like Linux did in early days. To use my chat application code just they need to mention in somewhere in this website (say at footer) a thanks to me with my personal website url that is http://sumanbiswas.com and just drop me a mail that they are using my code for my information. Whole code will be totally free of cost.

So this is my introduction of chat application source code and from next I shall post it by step by step.

Saturday, October 20, 2012

Send File from Server to Client using C# Socket Programming 5/6



Full codes are here...

Client code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace Client_Socket
{
//FILE TRANSFER USING C#.NET SOCKET - CLIENT
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("That program can transfer small file. I've test up to 850kb file");
IPAddress[] ipAddress = Dns.GetHostAddresses("localhost");
IPEndPoint ipEnd = new IPEndPoint(ipAddress[0], 5656);
Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
clientSock.Connect(ipEnd);


byte[] clientData = new byte[1024 * 5000];
string receivedPath = "C:/";

int receivedBytesLen = clientSock.Receive(clientData);

int fileNameLen = BitConverter.ToInt32(clientData, 0);
string fileName = Encoding.ASCII.GetString(clientData, 4, fileNameLen);

Console.WriteLine("Client:{0} connected & File {1} started received.", clientSock.RemoteEndPoint, fileName);

BinaryWriter bWrite = new BinaryWriter(File.Open(receivedPath + fileName, FileMode.Append)); ;
bWrite.Write(clientData, 4 + fileNameLen, receivedBytesLen - 4 - fileNameLen);

Console.WriteLine("File: {0} received & saved at path: {1}", fileName, receivedPath);

bWrite.Close();
clientSock.Close();
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("File Sending fail." + ex.Message);
}

}
}
}



Send File from Server to Client using C# Socket Programming 3/6



4) Server Action: These codes are not directly related with socket programming. This is using to read and send file to client.


string fileName = "test.txt";// "Your File Name";

string filePath = @"C:\FT\";//Your File Path;

byte[] fileNameByte = Encoding.ASCII.GetBytes(fileName);


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

byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length];

byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length);


fileNameLen.CopyTo(clientData, 0);

fileNameByte.CopyTo(clientData, 4);

fileData.CopyTo(clientData, 4 + fileNameByte.Length);


These lines of code reading some particular file from local drive and string its data in byte array “clientData”. File data need to store in array with raw byte format to send these to client. With data file name size string at initial of file data. This is predefined between client and server and it needs to do, otherwise client will not get file name which is sending by server.


For my case I am using first four byte to represent file name length and form 5th byte file name is storing. So all file data will store after file name.


5) Server Action: Now file data is in byte array and it needs to send to client. The same thing is happening by using below code with the help of client socket (clientSock) object, which was created during client request acceptance.


clientSock.Send(clientData);


Basically server application task ends here for small file transfer. Remaining code has used for some decoration and socket closing related things.


5) Client Action: Now again turn comes to client and it will perform below tasks:


byte[] clientData = new byte[1024 * 5000];

string receivedPath = "C:/";


int receivedBytesLen = clientSock.Receive(clientData);


Here first two lines are just creating byte array to store server data and path is used to decide where data to be save. In my code, I am saving data in C: drive.


Last line is start receiving data from server. Whenever client socket starts receiving server data then it returns length of data which has captured in a integer variable.



Wednesday, November 21, 2007

File Transfer using C# .Net Socket Programming 2/3


Phase 3, Break communication channel and release resources: When last slice of byte data saved at server, client and server close the socket object and release all resource like file stream, socket object etc.

By that way a file transferred from client to server. But there has no way to call a client from server and send file. My example describe how to send file from client to server but can you imagine how opposite done? Yes if you able learn client to server data transfer properly then it is very easy. Try your self first, if failed then try it again and continue at least three times, then you will able to do it. But….but again failed then ask me I will help you about it :-).

For code url is:

Client Code:

[C#]

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace Client_Socket
{
//FILE TRANSFER USING C#.NET SOCKET PROGRAMMING - CLIENT
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("That program can transfer small file. I've test up to 850kb file");
IPAddress[] ipAddress = Dns.GetHostAddresses("localhost");
IPEndPoint ipEnd = new IPEndPoint(ipAddress[0], 5656);
Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);


string fileName = "Your File Name";
string filePath = "Your File Path";
byte[] fileNameByte = Encoding.ASCII.GetBytes(fileName);

byte[] fileData = File.ReadAllBytes(filePath + fileName);
byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length];
byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length);

fileNameLen.CopyTo(clientData, 0);
fileNameByte.CopyTo(clientData, 4);
fileData.CopyTo(clientData, 4 + fileNameByte.Length);

clientSock.Connect(ipEnd);
clientSock.Send(clientData);
Console.WriteLine("File:{0} has been sent.", fileName);
clientSock.Close();
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("File Sending fail." + ex.Message);
}

}
}
}
[Visual Basic]

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Namespace Client_Socket
'FILE TRANSFER USING C#.NET SOCKET PROGRAMMING- CLIENT
Class Program
Private Shared Sub Main(ByVal args As String())
Try
Console.WriteLine("That program can transfer small file. I've test up to 850kb file")
Dim ipAddress As IPAddress() = Dns.GetHostAddresses("localhost")
Dim ipEnd As New IPEndPoint(ipAddress(0), 5656)
Dim clientSock As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP)


Dim fileName As String = "Your File Name"
Dim filePath As String = "Your File Path"
Dim fileNameByte As Byte() = Encoding.ASCII.GetBytes(fileName)

Dim fileData As Byte() = File.ReadAllBytes(filePath + fileName)
Dim clientData As Byte() = New Byte(4 + fileNameByte.Length + (fileData.Length - 1)) {}
Dim fileNameLen As Byte() = BitConverter.GetBytes(fileNameByte.Length)

fileNameLen.CopyTo(clientData, 0)
fileNameByte.CopyTo(clientData, 4)
fileData.CopyTo(clientData, 4 + fileNameByte.Length)

clientSock.Connect(ipEnd)
clientSock.Send(clientData)
Console.WriteLine("File:{0} has been sent.", fileName)
clientSock.Close()
Console.ReadLine()
Catch ex As Exception
Console.WriteLine("File Sending fail." & ex.Message)
End Try

End Sub
End Class
End Namespace


Tuesday, November 20, 2007

File Transfer using C# .Net Socket Programming 3/3



Continued code...
Server Code:
[C#]

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace beginSocketServer
{
//FILE TRANSFER USING C#.NET SOCKET PROGRAMMING - SERVER
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("That program can transfer small file. I've test up to 850kb file");
IPEndPoint ipEnd = new IPEndPoint(IPAddress.Any, 5656);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
sock.Bind(ipEnd);
sock.Listen(100);
Socket clientSock = sock.Accept();

byte[] clientData = new byte[1024 * 5000];
string receivedPath = "e:/";

int receivedBytesLen = clientSock.Receive(clientData);
int fileNameLen = BitConverter.ToInt32(clientData, 0);
string fileName = Encoding.ASCII.GetString(clientData, 4, fileNameLen);
Console.WriteLine("Client:{0} connected & File {1} started received.", clientSock.RemoteEndPoint, fileName);
BinaryWriter bWrite = new BinaryWriter(File.Open(receivedPath + fileName, FileMode.Append)); ;
bWrite.Write(clientData, 4 + fileNameLen, receivedBytesLen - 4 - fileNameLen);
Console.WriteLine("File: {0} received & saved at path: {1}", fileName, receivedPath);

bWrite.Close();
clientSock.Close();
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("File Receiving fail." + ex.Message);
}
}
}
}

[Visual Basic]

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Namespace beginSocketServer
'FILE TRANSFER USING C#.NET SOCKET PROGRAMMING- SERVER
Class Program
Private Shared Sub Main(ByVal args As String())
Try
Console.WriteLine("That program can transfer small file. I've test up to 850kb file")
Dim ipEnd As New IPEndPoint(IPAddress.Any, 5656)
Dim sock As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP)
sock.Bind(ipEnd)
sock.Listen(100)
Dim clientSock As Socket = sock.Accept()

Dim clientData As Byte() = New Byte(1024 5000 - 1) {}
Dim receivedPath As String = "e:/"

Dim receivedBytesLen As Integer = clientSock.Receive(clientData)

Dim fileNameLen As Integer = BitConverter.ToInt32(clientData, 0)
Dim fileName As String = Encoding.ASCII.GetString(clientData, 4, fileNameLen)

Console.WriteLine("Client:{0} connected & File {1} started received.", clientSock.RemoteEndPoint, fileName)

Dim bWrite As New BinaryWriter(File.Open(receivedPath + fileName, FileMode.Append))


bWrite.Write(clientData, 4 + fileNameLen, receivedBytesLen - 4 - fileNameLen)

Console.WriteLine("File: {0} received & saved at path: {1}", fileName, receivedPath)

bWrite.Close()
clientSock.Close()
Console.ReadLine()
Catch ex As Exception
Console.WriteLine("File Receiving fail." & ex.Message)
End Try
End Sub
End Class
End Namespace