#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How would connect to Facebook using socket programming in python?
Description

To know how to connect fb using python socket programming using python3.

Process

   import socket module.

  Create socket object.

   Within socket object, we must pass the socket_family, socket_type.

   Get host name(fb).

   Connect socket with host_ip using s.connect().

Sapmle Code

#import socket and sys module
import socket
import sys
try:

#define socket family
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print (“Socket successfully created”)
except socket.error as err:
print (“socket creation failed with error”,(err))
#default port
port = 80
try:
host_ip = socket.gethostbyname(‘www.facebook.com’)
except socket.gaierror:

#exit the system if error occurs
print (“there was an error resolving the host”)
sys.exit()

#connecting to the server
s.connect((host_ip, port))
print (“The socket has been connected to
facebook \n”,(host_ip))

Screenshots